+ 3
Nested for loop
How would you create: 54321 4321 321 21 1 in a nested for loop
3 odpowiedzi
+ 3
a = ''
for i in range(5,0,-1):
for j in range(i,0,-1):
a += str(j)
print(a)
a=''
+ 1
Was an assignment in school. Couldnt figure it out for some reason.
0
Why would you want to use nested loops if you can write a function which does the same for natural numbers of arbitrary length without:
https://code.sololearn.com/ckvDz9Xkl2db
If you cannot import math for whatever reasons, you can still determine the number of digits. Convert the integer to a string and cound the letters using the len() function.