How to solve this | Sololearn: Learn to code for FREE!

+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. ...

12/5/2021 5:35:06 AM

Luceepher

36 Answers

New Answer

+9

Luceepher You can also try this: print ("""1.2.3.4.5.6.7.8.9.""")

+9

Luceepher Here is with loop: [print(str(i) + '.') for i in range(1, 10)]

+6

Your code will be Print(''' 1. 2. 3. 4. 5. 6. 7. 8. 9. ''') Hope you like that

+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.

+4

i=1 while(i<=9): print(i, ".", sep="") i = i+1 # Keep learning & happy coding :D

+4

print("\n".join([str(i)+"." for i in range(1,10)]))

+3

Luceepher Don't put space after each dot(.)

+3

A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Yeah you are right I make it. Thanks

+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}.")

+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.

+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.''')

+2

A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ here is it ☝

+2

for i in range(1, 11): print(f"{i}.")

+2

In java, for(int i = 1; i <= 9; i++){ System.out.println(i+".");

+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

+2

public class Program { public static void main(String[] args) { for(int i=0; i<=10; i++) { System.out.println(i+"."); } } }

+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.

+2

sajad rajabi Yeah, and: print("1.") print() print("2.") ...

+2

Philip Carlin That's in JS, but not in Python, he/she ask that in Python.

+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