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 )
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!
+ 1
Esteban Rueda now it totally depends upon your requirements. You can always put a condition inside the while loop to break out.
0
And how am I suppose to change the value in order for it to not keep going in an infinite loop?
0
Add 'number += 1' under 'total += number'. Also, you may indent your print if you want to print each step.