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)
#9
(Nov-07-2022, 05:57 PM)deanhystad Wrote: To convert 13 to 3 there is a math operation you can use, or you could convert the number to a string and only use the last digit. Here's a list of Python math operators.

https://www.w3schools.com/python/python_operators.asp.

I would not print numbers and colons, but if you want to do it that way you can. Here's info about the print command.

https://realpython.com/python-print/

I would make a string of numbers and colons, and print the string. This is a pretty exhaustive list of string operators wiith examples.

https://pythongeeks.org/strings-in-python/

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.
Reply


Messages In This Thread
RE: Write loops that generate the given output. - by lilliancsk01 - Nov-08-2022, 06:42 AM

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