#๐ csc for loops assignment
24 messages ยท Page 1 of 1 (latest)
@mellow ginkgo
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
is this cmu academy
its prairelearn
nvm lmao
Do you have anything in particular that you need help on?
yeah im just having trouble figuring out how to code the pattern
i have the bottom and enclosed ascii stuff
but the inside is super wonky and when i call the function gives me a weird amount characters in the middle
i just dont know whar order of operations to do in order to fix it
And you have to use for loops for this?
That's kind of annoying cause I don't think you need them lol
yeah they want loops specifically lol
Something that might help is not worrying about creating two separate variables for the first two lines and just print out the same line twice.
Secondly I don't think you need to loop over AND multiply the string, just use one or the other and since you need to use for loops, just use the for loop to keep extending the string.
Maybe coming up with slightly more meaningful names might also help, like start_end and middle and then sticking to them. You don't need to set
inner1 = charB
inner2 = charB
If we can just use the same things over and over again
okay
I mean, if I was doing this I would even break this down into two separate functions that a third function calls, one that prints the first patten that you call twice and another function that prints the second kind of pattern.
!e
def print_instrument_unit(instrument: int) -> None:
if instrument < 0:
raise ValueError("Instrument must be a non-negative integer")
start_end = "||"
middle = "~#"
first_pattern = ""
first_pattern += start_end
for _ in range(instrument * 2 + 1):
first_pattern += middle
first_pattern += start_end
print(first_pattern)
print(first_pattern)
second_pattern = ""
second_pattern += "+"
for _ in range(instrument + 1):
second_pattern += "=*=*"
second_pattern += "+"
print(second_pattern)
print_instrument_unit(4)
print_instrument_unit(3)
print_instrument_unit(2)
print_instrument_unit(1)
print_instrument_unit(0)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | ||~#~#~#~#~#~#~#~#~#||
002 | ||~#~#~#~#~#~#~#~#~#||
003 | +=*=*=*=*=*=*=*=*=*=*+
004 | ||~#~#~#~#~#~#~#||
005 | ||~#~#~#~#~#~#~#||
006 | +=*=*=*=*=*=*=*=*+
007 | ||~#~#~#~#~#||
008 | ||~#~#~#~#~#||
009 | +=*=*=*=*=*=*+
010 | ||~#~#~#||
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/5QWCIJMHVL7ITFBTVMETLUNX5E
okay thanks so much!
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ csc for loops assignment