Python Forum
Please check whether the code about the for loop question is correct. (SyntaxError)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please check whether the code about the for loop question is correct. (SyntaxError)
#11
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Many iterations for loop question adesimone 9 1,856 Nov-12-2022, 07:08 PM
Last Post: deanhystad
  Beginner Python Question: FIzz Buzz using while loop camoyn13 2 1,809 Sep-20-2022, 09:00 AM
Last Post: deanhystad
  Is that code correct? Sameh 7 2,985 May-22-2021, 04:29 PM
Last Post: Sameh
  Repeat question (for loop) rs74 7 6,506 Jun-17-2020, 03:17 PM
Last Post: rs74
  Question about running comparisons through loop from input value Sunioj 2 2,414 Oct-15-2019, 03:15 PM
Last Post: jefsummers
  Please check code Evgeniy2019 4 3,088 Apr-05-2019, 06:37 PM
Last Post: Evgeniy2019
  SyntaxError: Invalid syntax in a while loop ludegrae 3 14,758 Dec-18-2018, 04:12 PM
Last Post: Larz60+
  Syntax error for code that seems correct mcnhscc39 4 3,600 Nov-15-2018, 08:40 PM
Last Post: j.crater
  while loop question Tripler 4 2,962 Jul-24-2018, 06:37 AM
Last Post: buran
  Loop question kraven 3 3,642 Sep-10-2017, 07:31 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020