+ 4
any alternatives?
So the question was "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. ..." and my answer was: l = [1,2,3,4,5,6,7,8,9] for lis in l: print(str(lis) + ".") I know that is a for loop and I felt like cheating because for loop is the only one came up on my mind. any alternatives?
7 Respostas
+ 4
w/o cheating 😉
print("""
1.
2.
3.
4.
5.
6.
7.
8.
9.""")
+ 5
for i in range(1,10):
print(str(i)+".")
+ 3
for i in range(9):
print(i+1,end=".\n")
+ 2
print (*list(str(x) + '.' for x in range(1, 10)),sep = "\n")
it is one line.
+ 1
try this:
def lb(x):
if x < 10:
print(str(x)+'.')
x += 1
return lb(x)
lb(1)
+ 1
How about this?
from string import digits
print('.\n'.join(list(digits[1:])+['']))