- 1

How to 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. ...

5th Dec 2021, 5:35 AM
Yusuff
Yusuff - avatar
38 Antworten
+ 10
Luceepher You can also try this: print ("""1.2.3.4.5.6.7.8.9.""")
5th Dec 2021, 6:38 AM
A͢J
A͢J - avatar
+ 9
Luceepher Here is with loop: [print(str(i) + '.') for i in range(1, 10)]
5th Dec 2021, 6:00 AM
A͢J
A͢J - avatar
+ 6
Your code will be Print(''' 1. 2. 3. 4. 5. 6. 7. 8. 9. ''') Hope you like that
5th Dec 2021, 2:20 PM
Alokesh Maitra
+ 5
i=1 while(i<=9): print(i, ".", sep="") i = i+1 # Keep learning & happy coding :D
5th Dec 2021, 9:39 AM
SoloProg
SoloProg - avatar
+ 5
public class number { public static void main(String[] args) { for(int i =1; i<=9; i++){ System.out.println(i+"."); } } } Hope it may help.
5th Dec 2021, 8:51 PM
Kamogelo Lebelo
+ 5
print("\n".join([str(i)+"." for i in range(1,10)]))
7th Dec 2021, 4:32 AM
Pallavi Bhardwaj
Pallavi Bhardwaj - avatar
+ 3
Luceepher Don't put space after each dot(.)
5th Dec 2021, 5:51 AM
A͢J
A͢J - avatar
+ 3
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Yeah you are right I make it. Thanks
5th Dec 2021, 5:54 AM
Yusuff
Yusuff - avatar
+ 3
Luceepher here is a simple way as A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ was pointing out .. for i in [1,2,3,4,5,6,7,8,9]: print(f"{i}.")
5th Dec 2021, 7:08 AM
BroFar
BroFar - avatar
+ 3
Try it: for i in range(1,11): toString = str(i) print(toString + ".") or for i in range(1,11): print(str(i) + ".") There are more alternatives you can get. Maybe this is a way to solve it.
6th Dec 2021, 2:26 AM
Viktoras
Viktoras - avatar
+ 3
I tried this one and worked cool for i in range(1,10): print(i,end='.\n') Also this: Print('''1. 2. 3. 4. 5. 6. 7. 8. 9.''')
6th Dec 2021, 8:38 AM
Krishna Jayanth
Krishna Jayanth - avatar
5th Dec 2021, 5:49 AM
Yusuff
Yusuff - avatar
+ 2
for i in range(1, 11): print(f"{i}.")
6th Dec 2021, 8:22 AM
Ibrahim Muhammad
Ibrahim Muhammad - avatar
+ 2
In java, for(int i = 1; i <= 9; i++){ System.out.println(i+".");
6th Dec 2021, 2:57 PM
Strt Tmknsn
Strt Tmknsn - avatar
+ 2
You can do it with a loop or in a single string variable: people = [put them in order here] for i in range (9): print(str(i) + ". " + people[i]) Or if u only care about 1-9: print("1.\n2.\n3.\n4.\n5.\n6.\n7.\n8.\n9.") When the program finds \n in a string, it will think it is a new line
6th Dec 2021, 4:51 PM
farima4
farima4 - avatar
+ 2
public class Program { public static void main(String[] args) { for(int i=0; i<=10; i++) { System.out.println(i+"."); } } }
6th Dec 2021, 5:05 PM
Jitender soni
+ 2
Try this: for numbers in range(1, 10): print(f"{numbers}.") The explication: I make a for loop in the range from 1 to 9 (10 in the code because range subtracts 1 from the only or second number in the range parameter, that is, 10-1 is 9), the loop would be like this, but putting a print (variable_of_the_loop_for ) with id (? amount of spaces, at least 1 spacez otherwise it gives an error): 1 2 3 4 5 6 7 8 9 In order not to have to type the 9 numbers. Then I give the identification, then an f-string that is written print (f "{variable} text") in {} you put the name of the variable or operation, otherwise an error appears, then the code is print (f " {numbers}. ") the result of this would be: 1. 2. 3. 4. 5. 6. 7. 8. 9. Hope you understand, a simpler way would be instead of f-string to use string concatenation, for example: for i in range (1, 9): print (numbers + ".") Well, so far my explanation. Ask me anything. Greetings.
6th Dec 2021, 7:11 PM
CGO!
CGO! - avatar
+ 2
sajad rajabi Yeah, and: print("1.") print() print("2.") ...
6th Dec 2021, 11:01 PM
CGO!
CGO! - avatar
+ 2
Philip Carlin That's in JS, but not in Python, he/she ask that in Python.
7th Dec 2021, 12:15 AM
CGO!
CGO! - avatar
+ 2
Why I really love Python: print('\n'.join([ '{}.'.format(number) for number in range(1, 10) ])) - [number for number in range (1, 10)] is a list of numbers between 1 and 9 - '{}.'.format(number) appends a dot after each number - '\n'.join(list) joins list items with newlines, thus putting each one in its line
7th Dec 2021, 12:20 AM
Emerson Prado
Emerson Prado - avatar