How do I solve this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How do I solve this?

You need to make a program for a leaderboard. The program needs to output the numbers 1 to 9, each on a separate line, followed by a dot: 1. 2. 3. ...

21st Jun 2021, 11:40 PM
Mariana lima
Mariana lima - avatar
9 Answers
+ 13
print(*range(1, 10), sep=".\n", end=".") https://code.sololearn.com/cUf1BnJlGwSm
22nd Jun 2021, 5:21 AM
David Ashton
David Ashton - avatar
+ 6
You can use "for": for i in range(1, 10): print(str(i) + '.')
22nd Jun 2021, 3:05 AM
SammE
SammE - avatar
+ 2
I did it!!!!! print ('1.' '\n2.' '\n3.' '\n4.' '\n5.' '\n6.' '\n7.' '\n8.' '\n9.') Python 3 😉
22nd Jun 2021, 12:00 AM
Mariana lima
Mariana lima - avatar
+ 2
Mariana lima 👍 here is another option. def leaderboard(n): for i in range(n): string=f'{i+1}.\n' print(string) if __name__=="__main__": n=9 leaderboard(n)
22nd Jun 2021, 12:49 AM
you are smart. you are brave.
you are smart. you are brave. - avatar
+ 2
Aathisankar Good idea, but he comma in the print() function inserts an unwanted space before the period. The default separator is a space unless you specify something else with sep=
23rd Jun 2021, 9:33 AM
David Ashton
David Ashton - avatar
+ 2
Aathisankar Yes. print(x, sep='.') and print(x, '.', sep='') both do the same thing.
23rd Jun 2021, 12:46 PM
David Ashton
David Ashton - avatar
+ 1
for i in range(9): print(i+1,'.')
23rd Jun 2021, 8:57 AM
Aathi Sankar
+ 1
Then this will do for i in range(9): print(I+1,'.',sep='')
23rd Jun 2021, 10:05 AM
Aathi Sankar
+ 1
for u in range(1,10): print (u , ".")
23rd Jun 2021, 5:25 PM
David Montes
David Montes - avatar