Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

suyuneo
4,502 PointsCan't go out of stock
Hi I have an issue with my vending machine program... Here is a link: https://w.trhou.se/r746h3m1js And below is the code:
sodas = ["Pepsi", "Cherry Coke Zero", "Sprite"]
chips = ["Doritos", "Fritos"]
candy = ["Snickers", "M&Ms", "Twizzlers"]
while True:
choice = input("Would you like a SODA, some CHIPS or a CANDY? ").lower()
try:
if choice == 'soda':
snack = sodas.pop()
elif choice == 'chips':
snack = chips.pop()
elif choice == 'candy':
snack = candy.pop()
else:
print("Sorry, I didn't get that!")
continue
except IndexError:
print("Sorry! We're all out of {}!".format(choice))
else:
print("Here's your {}: {}".format(choice,snack))
The answer I get from my console is: Would you like a SODA, some CHIPS or a CANDY? If I enter chips 3 times, I will get this response:
Sorry! We're all out of chips!
Here's your chips: Doritos
Please advice if I missed out something somewhere? Thank you!
2 Answers

Steven Parker
225,652 PointsThe code looks OK, and I get a different result when I run it:
Would you like a SODA, some CHIPS or a CANDY? chips
Here's your chips: Fritos
Would you like a SODA, some CHIPS or a CANDY? chips
Here's your chips: Doritos
Would you like a SODA, some CHIPS or a CANDY? chips
Sorry! We're all out of chips!
Would you like a SODA, some CHIPS or a CANDY?

suyuneo
4,502 PointsHmm, that's really weird!

Steven Parker
225,652 PointsIs it possible something changed after the snapshot was made?

suyuneo
4,502 PointsNo, I promise no changes were made after the snapshot was taken. :/

Steven Parker
225,652 PointsSo is it still behaving differently?