How can I make this more efficient : python | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

How can I make this more efficient : python

Rather than going one by one how can I make this question easier Question: make a leaderboard list 1-9 Eg; 1. 2. 3. Etc. My code: print("1.") print("2.") print("3.") print("4.") print("5.") print("6.") print("7.") print("8.") print("9.")

4th Jul 2021, 4:09 AM
Eren Ozer
8 Réponses
+ 3
either by using a loop or by outputting only one string: for i in range(1,10): print(str(i)+".") or print("1.\n2.\n3.\n4.\n5.\n6.\n7.\n8.\n9.") "\n" is the new line char
4th Jul 2021, 4:13 AM
visph
visph - avatar
+ 2
Use a for loop for i in range(10): print(i)
4th Jul 2021, 4:11 AM
Krish
Krish - avatar
+ 2
visph , there is a "n" missing in print("1.\n2.\3.\n4.\n5.\n6.\n7.\n8.\n9.") just before the number 3. ;-)
4th Jul 2021, 10:08 AM
Lothar
Lothar - avatar
+ 1
Lothar thank's for the typo: corrected ;)
4th Jul 2021, 2:21 PM
visph
visph - avatar
+ 1
Loops must be a better way to do this because in that you need not to use new line character
5th Jul 2021, 3:37 AM
Sumit Kumar
Sumit Kumar - avatar
0
visph i tried the new line char but i think i did it wrong since it ended like this 1. 2. 3. Etc Where there was a space after the first one. How would i fix that
4th Jul 2021, 4:15 AM
Eren Ozer
0
because you put space after (and maybe before) \n... the expected output must have no spaces at all ;P
4th Jul 2021, 4:18 AM
visph
visph - avatar
0
visph thank you !
4th Jul 2021, 4:25 AM
Eren Ozer