How can i stop this Infinite While Loop - Python
ferzan saglam
ferzans97 at gmail.com
Wed Oct 30 07:55:15 EDT 2019
I have tried many ways to stop the infinite loop but my program doesn't seem to stop after 10 items! It keeps going...!)
---------------------------
total = 0
while True:
print('Cost of item')
item = input()
if item != -1:
total += int(item)
else:
break
print(total)
---------------------------
The output I am aiming for is for the code to stop asking 'Cost of item' after 10 inputs or until -1 is typed, but the code repeats itself on an infinite loop. I cannot seem to stop the infinite loop.
Thanks for any help in advance.
More information about the Python-list
mailing list