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 Basics (2015) Python Data Types Use .split() and .join()

It is frustrating!

What is wrong with this. I spent too much time for solve this. It supposed to be an easy task.

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are: {}.".format(display_menu)
display_menu = ", ".join(sundaes)

1 Answer

andren
andren
28,558 Points

The main issue with your code is that you reference the display_menu variable before you actually define it, Python reads your script from top to bottom, so in your third line of code you are telling Python to look up a variable that does not yet exist, which won't work. Moving the display_menu variable's declaration to be on top of the menu variable declaration will fix that issue and let you pass the challenge.

On top of that though I would like to point out that you don't really need the display_menu variable in the first place, since you are only using the contents of the variable in one place it is not necessary to store it in a variable. Variables are mainly useful for storing info that will be referenced multiple times throughout your code, or that will only be used at a later point.

Instead of using a variable you can just pass the value directly in to the format call like this:

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are: {}.".format(", ".join(sundaes))