Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!