How can i stop this Infinite While Loop - Python
Matheus Saraiva
matheus.saraiva at gmail.com
Wed Oct 30 08:13:30 EDT 2019
m 30/10/2019 08:55, ferzan saglam escreveu:
> total = 0
> while True:
>
> print('Cost of item')
> item = input()
>
> if item != -1:
> total += int(item)
> else:
> break
>
> print(total)
The program does not stop because its code does not contain any deals
that make the loop stop after 10 rounds. You can simply implement a
counter that counts the number of times the loop has passed.
You also did not convert item to int to make the comparison.
total = 0
rounds = 0
while rounds <= 10:
print('Cost of item')
item = input()
if int(item) > -1:
total += int(item)
rounds += 1
else:
break
print(total)
More information about the Python-list
mailing list