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 trial

Python Python Collections (2016, retired 2019) Lists Pop

My 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))

error 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$

2 Answers

input 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

Hi KRIS NIKOLAISEN,

The problem was, as you said These lines: snack == sodas.pop() should use an assignment (=) operator

Thank you!