(New to Python) Shopping List Code

ferzan saglam ferzans97 at gmail.com
Mon Oct 28 09:42:46 EDT 2019


How can I stop this code when -1 is typed or at a maximum item count of ten.
At the moment the code seems to be in a infinite loop meaning it keeps on asking for an entry until -1 is typed 


total = 0	 	       	  	  	  	    	   	
while True:	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
  print('Cost of item')	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
  item = input()	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
  if item != -1:	 	       	  	  	  	    	   	
    total = total + item	 	       	  	  	  	    	   	
  if item == -1:	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
      break	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
print(total)


More information about the Python-list mailing list