For leaderboard practice thing, I tried a recursive loop thing. What did I do wrong? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

For leaderboard practice thing, I tried a recursive loop thing. What did I do wrong?

n = 1 if n<10: print( n + ".") n = n + 1 That’s what I got. Set n to 1. If n<10, print n and period. Add 1 to n. I keep getting syntax error with the print line. “\.” Didnt do anything (i thought maybe the period is something). Is the app just limiting my ability to use variables at this time?

27th Aug 2021, 2:56 AM
Yimin
5 Answers
+ 1
The syntax error stems from the fact that you're trying to add/concatenate an integer with a string. But your code has other issues, not least of all the fact that there is no loop.
27th Aug 2021, 3:06 AM
Simon Sauter
Simon Sauter - avatar
+ 1
Yimin it should be print(str(n) + ".")
27th Aug 2021, 3:09 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
There's a colon missing at the end of the first line. The second line needs to be indented.
27th Aug 2021, 3:16 AM
Simon Sauter
Simon Sauter - avatar
0
for n in range(1,10): print(str(n) + “.”) Would this work? Thanks Simon!
27th Aug 2021, 3:14 AM
Yimin
0
for n in range(1,10): print( str(n) + ".") Mistakes colon missing Print should be indented to for
27th Aug 2021, 3:17 AM
Pariket Thakur
Pariket Thakur - avatar