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 trialpriyanka shukla
3,051 Pointsmy_colors=[ red, blue, green, yellow, white ] why is a name error being shown with the first item of this list?
why is this name error being shown?
my_colors=[ red, blue, purple, yellow, white ]
1 Answer
eck
43,038 PointsPython is interpreting all those colors as variable names, but since those variables are not defined Python is throwing an error. I suspect your intention was for the colors in the list to be strings
(how text is referred to in most programming languages).
To change these from variables to strings all you need to do is wrap them in quotes, ['red', 'blue', etc...]
Joshua Tiedtke
5,647 PointsJoshua Tiedtke
5,647 PointsColors are strings so you have to write them like: "red", "blue", ...
Also your list is supposed to be called colors not my_colors.