Python Forum

Full Version: Please check whether the code about the for loop question is correct. (SyntaxError)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Are you posting to the wrong forum? This is a Python forum, not C++. What are you doing with the curly {} brackets?

Kidding aside, this is gibberish and the errors are numerous. There are unterminated f'strings (missing trailing } and '), or at least they are not terminated on the correct line in the program. You have for loops without colons. You access uninitialized variables (n, l). By the way, never use l (lower case L) or O (upper case o) as variable names. They look too much like one and zero.

You can write this using 1 print statement, but the code that builds the string should not be in the print statement. It should look like this:
size = int(input("Enter size "))
lines = make_the_lines  # Replace with code to make the lines
print("\n".join(lines))
Personally, I think it makes more sense to print the lines as they are created.
size = int(input("Enter size "))
for number in size:
    line = make_the_line  # Replace with code that makes line for number
    print(line)
Pages: 1 2