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

Weiwei Peng
Weiwei Peng
1,218 Points

Don't know what is wrong with my code. Can someone help me?

Below is my code for the 3 code challenges. I passed the first two. And I failed on the third one. The message kept telling me task 1 is no longer passing. I really don't know what is going on. Is anything wrong with my last line of code?

sundaes = available.split(";") menu = "Our available flavors are: {}." menu.format(sundaes.join(","))

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're really close here! We need to do the assignment all on one line and the join statement is a little off. Take a look at the line you need for step 3:

menu = "Our available flavors are: {}.".format(", ".join(sundaes))

We take our sundaes string which is currently split up at the semicolons. Now we join sundaes back up but this time with a comma and a space. Then we take all that and squish it in where the curly brackets are in the menu string. Hope that clarifies things!

Weiwei Peng
Weiwei Peng
1,218 Points

what about the following line of code for step 3, would this do the same job as the line of code you gave out? menu.format(", ".join(sundaes))

Weiwei Peng
Weiwei Peng
1,218 Points

I did tried the code you gave in step 3 and I got the following message: Bummer! Did you use .join(", ")? I don't understand, Shouldn't this be '.join(sundaes)' instead of '.join(",")' ?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I really don't know what to say here. This is my code that passes for all steps:

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

The comma and space are supposed to come before the join. If I take the code above and copy/paste it into the challenge it passes all 3 steps.

Weiwei Peng
Weiwei Peng
1,218 Points

I got it. I missed a space out there- right behind the comma. The challenge is really picky. Thanks for the help!!