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 trialMargaret Maginnis
199 PointsMaking lists with a new var 'colors' added to 5 other things in the list. please help
I'm trying to create a new variable named 'colors'. Next I want to add 'colors' to my list along with five other things. How do I even begin?
name = "colors"
my_list = [red, blue, yellow]
my_list.append [name]
3 Answers
Chris Freeman
Treehouse Moderator 68,441 Points1 Make a new variable named colors.
A new variable is made by assigning something to a newly name object:
colors = something
2 Assign it to a list of at least 5 items.
A list is denoted by square brackets []
. Items inside are separated by commas
colors = []
3 They should be colors but I won't mark you off for that.
The names of colors are strings. String need to be enclosed in matching quotation marks.
colors = ['red', "blue", "green", "puce", 'ecru']
lambda
12,556 PointsThe exercise says "colors" but it really means strings representing colors.
# Example of a list of shapes (strings representing shapes).
shapes = [ "square", "circle", "rectangle", "triangle", "oval" ]
# example of list of "fruits" (or strings representing fruits)
fruits = [ "apple", "banana", "orange", "cherry", "lemon", "lime", "coconut" ]
In your code, you are missing quote marks, so python thinks they are variables:
my_list = [red, blue, yellow] #python will think red, blue, yellow are variables, not colors.
Margaret Maginnis
199 Pointsthanks everybody. I only get time to work on this intermittently but will continue. I appreciate all the help!