git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How can i stop this Infinite While Loop - Python


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.