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 trialmendelbakaleynik
1,009 PointsTrouble answering Question 1 of Code Challenge.
The Code Challenge Question is ; "I think it's time for a snack. Luckily I have a string full of types of ice cream sundaes. Unluckily, they're all in one string and the string has semi-colons in it too. Use .split() to break the available string apart on the semi-colons (;). Assign this to a new variable sundaes." I simply don't know what next step to take. Here is the code I came up with. I am obviously missing something obvious, but cannot seem to see it.
available = "banana split;hot fudge;cherry;malted;black and white"
available.split(';')
available.join + ';'.join(sundaes)
available = "banana split;hot fudge;cherry;malted;black and white"
available.split(';')
available.join + ';'.join(sundaes)
5 Answers
Carlos Federico Puebla Larregle
21,074 PointsIn task one you only have to "Use .split() to break the available string apart on the semi-colons (;). Assign this to a new variable sundaes.". You could do that like this:
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
Carlos Federico Puebla Larregle
21,074 PointsRemember not to forget the "=" operator to actually assign the String to the "menu" variable.
In the second task you have to create the "menu" variable and assign it the string "Our available flavors are:{}."
Then in the third task you have to format that string, placing in the "placeholder {}" the joined version of the variable "sundaes". Remember that we split the variable "sundaes" so we convert it into a list and then we are converting it to a string again. You could do it like this:
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are:{}.".format(", ".join(sundaes))
mendelbakaleynik
1,009 PointsOk, so the second task only passed once I copied Carlos's entire code into it. Adding the "=" operator did nothing. Also, that piece of code solved the second and third task in a row, requiring no additional coding. Why would it do that?
On a side question, for what purpose are the operators {} .". inserted in to the menu value? What purpose do they serve, since we didn't even use the curly braces as a placeholder when we ran ".format" to fill the menu with the "sundaes" variable?
Carlos Federico Puebla Larregle
21,074 PointsAdding the "=" operator didn't make pass the task because you have a dot at the end of the line. So
Task 1:
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
Task 2:
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are:{}."
Task 3:
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are:{}.".format(", ".join(sundaes))
You use the "{}" to put in there the string "banana split, hot fudge, cherry, malted, black and white". The one you had in the first place but with commas instead of ";".
mendelbakaleynik
1,009 PointsThanks for the help Carlos!
Predictably, I'm not understanding how to solve the next question either.
Let's add a new string variable for displaying our menu items. Make a new variable named menu that's set to "Our available flavors are: {}.".
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
menu "Our available flavors are: {}.".
Am I supposed to insert the value of the variable "available" into the wacka wackas?
Luke Armstrong
5,932 PointsI'm pretty sure the only thing you are missing here is the = after the word 'menu'.
Remember, anything not assigned to a variable won't be saved and accessible later on (which was your problem with the first part, as you did not assign the .split() to a variable). The = symbol is what tells python 'this is a variable and this is what it holds' so without it python thinks its just broken coding.
Hope this helps! Good luck!
mendelbakaleynik
1,009 PointsGotcha. I was confused by the grammar that Treehouse used to write the instructions. They put a period at the end of the sentence, to finish the sentence grammatically. I thought that the period was a piece of syntax,