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! While you're at it, check out some resources Treehouse students have shared here.
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 trialModou Sawo
13,141 PointsI'm reviewing; this code doesn't work on my mac, I can't figure out the problem.
It runs perfectly fine on workspaces.
sodas = ["Pepsi", "Diet coke", "Orange Soda"]
candy = ["Twizzlers", "Snickers Bar", "Candy Crush"]
chips = ["Potatos", "Barbeque Chips", "Pringles"]
while True:
try:
choice = input("Do you want a CANDY, CHIPS or SODA? ")
if choice == 'chips':
snack = chips.pop()
elif choice == 'soda':
snack = sodas.pop()
elif choice == 'candy':
snack = candy.pop()
else:
print("Sorry, I don't understand that")
continue
except IndexError:
print("Sorry, we are out of {}".format(choice))
else:
print("Here's your {}: {}".format(choice, snack))
1 Answer
Stuart Wright
41,120 PointsYour code works correctly for me on my Windows machine (although it goes on forever because there's no break clause to exit the loop).
My best guess as to why it doesn't work on your Mac would be that you are using an older version of Python - I believe Python 2.x comes installed on Mac OS by default, and the code above will only work on Python 3.x, which you can download here:
Modou Sawo
13,141 PointsModou Sawo
13,141 PointsYeah Stuart, I had the same realization this morning - it works when I run "python3 ......" Thanks!