0

Please help: loop until squared number reaches 20 digit length

https://code.sololearn.com/cgZz7IyfiPV0/?ref=app

23rd Oct 2022, 1:55 AM
Julia V
Julia V - avatar
5 Respuestas
+ 6
Julia V def Q9(): c = 0 i = 3 while i > 0: i = i**2 print(i) print() c = c + 1 if len(str(i)) > 20: break print(c) Q9()
23rd Oct 2022, 3:21 AM
BroFar
BroFar - avatar
+ 4
Yes Julia V you started assigning i as a string to begin with and your str(i) was only 1 char, the number 3 so it could never be longer that 20 in length and i as a string could only be 3 not the integer of 3 9 81 and so on to reach a character length of 20 def Q9(): c = 0 i = str(3) while len(i) >= 20: i = i**2 c = c + 1 print(c) Q9()
23rd Oct 2022, 3:32 AM
BroFar
BroFar - avatar
+ 3
You are welcome Julia V
23rd Oct 2022, 3:36 AM
BroFar
BroFar - avatar
+ 1
Thank you soo much BroFar ! Could you explain why my code didn't work?
23rd Oct 2022, 3:27 AM
Julia V
Julia V - avatar
+ 1
BroFar Got it! That makes sense. Thank you
23rd Oct 2022, 3:34 AM
Julia V
Julia V - avatar