0

Does anyone know how to stop this infinite while loop?

number = 1 total = 0 while (number * number) % 1000 != 0: total += number print( "Total is", total )

9th Dec 2019, 11:30 AM
Esteban Rueda
Esteban Rueda - avatar
4 Respuestas
+ 2
It's because you ain't changing the value of the variable number. It's always the same 1 and thus results in an infinite loop!
9th Dec 2019, 12:15 PM
Шащи Ранжан
Шащи Ранжан - avatar
+ 1
Esteban Rueda now it totally depends upon your requirements. You can always put a condition inside the while loop to break out.
9th Dec 2019, 4:33 PM
Шащи Ранжан
Шащи Ранжан - avatar
0
And how am I suppose to change the value in order for it to not keep going in an infinite loop?
9th Dec 2019, 1:49 PM
Esteban Rueda
Esteban Rueda - avatar
0
Add 'number += 1' under 'total += number'. Also, you may indent your print if you want to print each step.
9th Dec 2019, 4:10 PM
Morgane Zabzab