0
Please help: loop until squared number reaches 20 digit length
5 Antworten
+ 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()
+ 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()
+ 3
You are welcome Julia V
+ 1
Thank you soo much BroFar ! Could you explain why my code didn't work?
+ 1
BroFar
Got it! That makes sense. Thank you