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

The last step, in this challenge, is confusing to me. I don't really understand what it is I am supposed to do?

I was able to get through some other parts that had confused me before but now, I'm still stuck on this challenge, on what I think is the last step.

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

2 Answers

K Cleveland
K Cleveland
21,839 Points

Check this out:

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

This is what you should have had after part 2 of the challenge, correct? Well, part 3 asks you to:

  1. Combine sundaes list into a variable named display menu
  2. Each item is rejoined together by (", ").
  3. Reassign menu variable to use existing variable
  4. You'll need to use .format() as well as display_menu

So, now you know some things you need to do:

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes=available.split(';')
menu="Our available flavors are: {}." #should this line be here or somewhere else? 
display_menu+", ".join(sundaes) # I think you have a typo here :) 
menu.format(display_menu)  #What are you formatting? Where's the place holder {}? 

You're super close. Just need a bit of clean up. Good luck!

I'm not sure if that line should be somewhere else, it returned a passing result and allowed me to move on to the next step, which is the step that I'm on now. Ok, I'm not sure where the typo is... : / everything seems to be spelled correctly, I think. Unless, you are referring to the lack of parenthesis. In the example at the bottom of the video's page, it showed,

my_string+", ".join(my favorite colors)

So, perhaps I copied it down wrong. I kept having to switch back and forth between the video and the challenge because I couldn't remember exactly how everything was supposed to be typed out. So, I finally just wrote it down on a piece of paper that I could reference. I don't know what I'm formatting because of the wording of the last part, I don't really understand what is expected of me. The example given within the video, is as follows:

"My favorite flavors are: {}".format(", ").join(flavors)) 

The instructions in the last step seem to be asking us to do something a little different than what the video example showed us. I'm just plain confused with the last step.

K Cleveland
K Cleveland
21,839 Points

Ah, OK. I understand now. So, my first piece of advice to you would be to work to understand what each piece of code does. So let's look at it!

# list that contains strings "green", "black", "silver"
my_favorite_colors = ["green", "black", "silver"]
# string "My favorite colors are "
my_string = "My favorite colors are "
# this last line is more complicated
# my_string = "My favorite colors are "
# ",".join(my_favorite_colors) will output "green, black, silver"
#So the full line becomes "My favorite colors are green, black, silver"
my_string + ",  ".join(my_favorite_colors) 

HOWEVER

The challenge asks you to combine the sundaes list into a new variable named display_menu

display_menu+", ".join(sundaes)

Here, you have an undefined variable that you're trying to combine together into a string. You should be creating a new variable called "display_menu". Next, combine the sundaes list using join, and assign it to the display_menu variable.

Finally, the challenge asks you to:

  1. reassign the menu variable to use the existing variable
  2. and .format() to replace the placeholder
  3. with the new string in display_menu.

So let me clear it up:

  1. Menu does not use the new variable (display_menu) you created. This is simply asking you to make sure menu is going to use display_menu.
  2. This is basically telling you to use .format() in your answer
  3. You created a new string and assigned it to the display_menu. This is basically saying: When you use .format(), make sure the thing you're trying to format is display_menu.

Hopefully this will clear up some things. Good luck!