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

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points

why is my function not working

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

Moderator edited: Added Markdown to post so the code is readable in the Community. Please refer to the Markdown Cheatsheet when posting code to the Community for proper posting practices.

1 Answer

I think the error is where you used [} instead of {} inside of the last string in your 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()
  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))  # You used [}; Python expected you to use {}. Change [} to {} and you should be good to go!

I hope this helps. ~Alex

If this answered your question, please mark it as a Best Answer. Thank you!