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 trialMohammed Miah
195 PointsMy Code work: working on mac - python3
sodas = ["Pepsi", "Coke", "Sprite"] chips = ["Doritos", "Walkers"] candy = ["Snickers", "M&Ms", "Twizzlers"]
while True: choice = input("Would you like SODA, some CHIPS, or CANDY? ").lower()
try:
if choice == 'sodas':
snack == sodas.pop()
elif choice == 'chips':
snack == chips.pop()
elif choice == 'candy':
snack == candy.pop()
else:
print("Sorry, I didn't understand that.")
continue
except IndexError:
print("We're all out of {}! Sorry!".format(choice))
else:
print("Here's your {}: {}".format(choice, snack))
2 Answers
KRIS NIKOLAISEN
54,972 Pointsinput should return a string so I don't see how you got the error that the result is a list. What did you enter?
Some other things:
- It's confusing that you prompt for SODA but then check for sodas plural
- There is no means of exiting your loop
- These lines:
snack == sodas.pop()
should use an assignment (=) operator
Mohammed Miah
195 PointsHi KRIS NIKOLAISEN,
The problem was, as you said These lines: snack == sodas.pop() should use an assignment (=) operator
Thank you!
Mohammed Miah
195 PointsMohammed Miah
195 Pointserror message i get
would you like a SODA, CHIPS, or a CANDY? chips Traceback (most recent call last): File "vending_machine1.py", line 6, in <module> choice = input("would you like a SODA, CHIPS, or a CANDY? ").lower() AttributeError: 'list' object has no attribute 'lower' Pyhon Code$