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

Michael Little
Michael Little
2,514 Points

Why is my code not working??

I think I have everything put in correctly and have went over it multiple times. It is saying I haven't defined snack but it looks exactly like the videos, please help.

Michael Little
Michael Little
2,514 Points
<p> 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()
    if choice == 'soda':
        snack = sodas.pop()
    elif choice == 'chips':
        snack == chips.pop()
    elif choice == 'candy':
        snack = candy.pop()
    else:
        print("Sorry, I didn't understand that.")
        continue
    print("Here's your {}: {}".format(choice, snack))
</p>```
Michael Little
Michael Little
2,514 Points

also the <p>'s and ``` aren't in my code I just made a mistake formatting for the question.

2 Answers

Steven Parker
Steven Parker
231,269 Points

This line has a comparison operator (==) but I think you should have an assignment (=) there instead:

        snack == chips.pop()
Steven Parker
Steven Parker
231,269 Points

Michael Little — Glad to help. You can mark a question solved by choosing a "best answer".
Happy coding!