0

What's wrong with my solution

Problem: Strings 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. ... My solution: print('1. \n2. \n3. \n4. \n5. \n6. \n7. \n8. \n9.') was not accepted but it gives the same result as print(''' 1. 2. 3. 4. 5. 6. 7. 8. 9. ''') which was accepted.

6th Mar 2022, 11:25 AM
Mark
Mark - avatar
6 Antworten
+ 7
Mark Your code is correct after making modification which Simba did , but if the program asks you to print the numbers from 1 to Million , Are you will write all those numbers by your self , of course not, so I advise you to use range method and str method so your code will be for i in range(1,10): print(str(i) +'.')
6th Mar 2022, 11:39 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 5
You need to remove the space between '.' and '\. "1.\n2.\n3....."
6th Mar 2022, 11:25 AM
Simba
Simba - avatar
+ 2
Ok I see it now. The spaces were important. Thanks for the help.
6th Mar 2022, 11:58 AM
Mark
Mark - avatar
+ 1
n = int(input()) dot = '.' for i in range(1 , n+1): print(str(i)+dot) I've solved my coding problem from this one!
7th Mar 2022, 1:42 AM
Saad Khan
Saad Khan - avatar
0
Why do I need to remove the space between '.' and '\. "1.\n2.\n3....." When I run the code it gives exactly the same result. I could have used a range method but the problem was to output the numbers 1 to 9.
6th Mar 2022, 11:48 AM
Mark
Mark - avatar
0
You are to use the for loop with the Range built-in function in Python to solve it in case of next time the numbers are higher it will be easier to solve than write it all at once , or you can define your own function to all the work for you . E. G for x in range(1,10): Number = str(x) + "." print(Number) OR Make it a function def numbering(x,y): for I in range(x,y): Number = str(i) + "." print(Number) numbering(1,10) HOPE IT HELPS
7th Mar 2022, 1:21 PM
Abdallah Umar Jibir
Abdallah Umar Jibir - avatar