+ 3

Nested for loop

How would you create: 54321 4321 321 21 1 in a nested for loop

4th May 2017, 4:07 AM
Prospector
Prospector - avatar
3 Respuestas
+ 3
a = '' for i in range(5,0,-1): for j in range(i,0,-1): a += str(j) print(a) a=''
4th May 2017, 5:32 AM
Saeed Tafazzol
Saeed Tafazzol - avatar
+ 1
Was an assignment in school. Couldnt figure it out for some reason.
4th May 2017, 6:05 PM
Prospector
Prospector - avatar
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.
4th May 2017, 11:24 AM
Klaus-Dieter Warzecha
Klaus-Dieter Warzecha - avatar