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)
#1
print('\n'.join(f'{":".join(str(n)[-1]
for l in range(int(l/2+.5)))}{"" if l%2 else ":"}'
for n, l in (lambda n: ((l, n)
for l in range(n)))(int(input("Enter the size of the pattern:")))))

After I run the above code, a syntax error prompt out: unterminated string literal.
How can I fix the syntax error? Please check whether the code is correct.


Write a program that again generates a square, this time of a different pattern. You should again include code that checks the validity of the input value.

The example shows two different executions of the program. Your program code should be similar to the above program. Printing of digits should have wrap-around feature, i.e. after ‘9’ is ‘0’.

Enter the size of the pattern: 5

0:0:0

1:1:1

2:2:2

3:3:3

4:4:4

Enter the size of the pattern: 14

0:0:0:0:0:0:

1:1:1:1:1:1:

2:2:2:2:2:2:

3:3:3:3:3:3:

4:4:4:4:4:4:

5:5:5:5:5:5:

6:6:6:6:6:6:

7:7:7:7:7:7:

8:8:8:8:8:8:

9:9:9:9:9:9:

0:0:0:0:0:0:

1:1:1:1:1:1:

2:2:2:2:2:2:

3:3:3:3:3:3:
Reply


Messages In This Thread
Please check whether the code about the for loop question is correct. (SyntaxError) - by lilliancsk01 - Nov-07-2022, 03:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Many iterations for loop question adesimone 9 1,943 Nov-12-2022, 07:08 PM
Last Post: deanhystad
  Beginner Python Question: FIzz Buzz using while loop camoyn13 2 1,874 Sep-20-2022, 09:00 AM
Last Post: deanhystad
  Is that code correct? Sameh 7 3,068 May-22-2021, 04:29 PM
Last Post: Sameh
  Repeat question (for loop) rs74 7 6,576 Jun-17-2020, 03:17 PM
Last Post: rs74
  Question about running comparisons through loop from input value Sunioj 2 2,453 Oct-15-2019, 03:15 PM
Last Post: jefsummers
  Please check code Evgeniy2019 4 3,144 Apr-05-2019, 06:37 PM
Last Post: Evgeniy2019
  SyntaxError: Invalid syntax in a while loop ludegrae 3 14,833 Dec-18-2018, 04:12 PM
Last Post: Larz60+
  Syntax error for code that seems correct mcnhscc39 4 3,666 Nov-15-2018, 08:40 PM
Last Post: j.crater
  while loop question Tripler 4 3,008 Jul-24-2018, 06:37 AM
Last Post: buran
  Loop question kraven 3 3,715 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