The program offers items, has the user pay for items, gives the items, and updates the stock of each item. It seems to work more or less. I have 2 questions: I don’t know how to exit the vending machine program after the user answers “n” to “buy something else? (y/n): “. Is there a way to make the code
Tag: while-loop
How to solve StopIteration error in Python?
I have just read a bunch of posts on how to handle the StopIteration error in Python, I had trouble solving my particular example.I just want to print out from 1 to 20 with my code but it prints out error StopIteration. My code is:(I am a completely newbie here so please don’t block me.) Answer Any time you use
Python: How to end a while loop while it is running if the while condition changes during the loop?
I need some help with code in a text based game I am trying to make. My game uses health, and the code starts off with “while health>0:”, and in another point in the game, when health eventually =0, the loop still continues. How do I make the loop end when health=0, without finishing the whole loop. Here is an
How do I reverse a list using while loop?
Input list: [1, 2, 3, 4, 5] Output: [5, 4, 3, 2, 1] I know how to do it with for loop, but my assignment is to do it with while loop; which I have no idea to do. Here is the code I have so far: Answer I would say to make the while loop act like a for
Pause an infinite while loop with a single keypress
I’m new to python and I have been trying to find a simple way to pause an operating while-loop, making it possible to start it again from where it was paused. I have searched on Google for help and tips, but everything I find seems very complex. Is there a simple way to do this? I’ve read that you can