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

I have encountered an error in one of the objective questions in the split()&join() obj. question. What is the problem?

I have no idea on what went wrong in this piece of code. Back at my computer when I ran the same program (the only thing was that I also printed display_menu for reference), I got the required output. Can someone please let me know what it is and tell me if there is an error in my code or a problem in the question.

Thank You, Prateek

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

2 Answers

andren
andren
28,558 Points

I'll chalk it up to a problem with how the instructions are laid out, as it's very common for people to misunderstand the last part of this challenge.

This challenge has two intended solutions (though there are more than two ways to solve it), a short one and a long one which both ultimately do the same thing. The long version looks like this:

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

While the short one looks like this:

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

The way the challenge instructions are worded does make many people think that the ultimate goal of the challenge is to store the formatted menu in the display_menu variable, which is not illogical given it's name.

But as you can see from the intended solutions the challenge actually want the formatted menu to be stored back in the menu variable. In your solution you can actually accomplish this by simple changing the name of the display_menu variable to menu.

Torsten Lundahl
Torsten Lundahl
2,570 Points

You're on the right path, but you are formatting menu and assigning display_menu on the same line. Break them appart and format menu on the next line.

From this:

display_menu = menu.format(", ".join(sundaes))

To this:

display_menu = ", ".join(sundaes)
menu = menu.format(display_menu)