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 trialIvet Achieng
253 Pointswhy is red the variable being outputted when purple was my input?
I am confused
favorite_color =input("What is your favorite color?")
favorite_color = "purple"
print("The color", favorite_color, "is a great color!")
2 Answers
Shem Ogweno
15,393 PointsHello Ivet Achieng,
Here is one way of doing it.
favorite_color = input('What is your favorite color? ')
print('The color ' + favorite_color + ' is a great color!')
Asher Orr
Python Development Techdegree Graduate 9,409 PointsHi Ivet! Let me explain to you what your code is doing:
favorite_color =input("What is your favorite color?")
#prompts user to enter their favorite color & stores their response in the variable favorite_color.
favorite_color = "purple"
#assigns favorite_color the value "purple"
#even if the user inputted something like "yellow" or "green" earlier, the favorite_color variable now stores the value "purple."
print("The color", favorite_color, "is a great color!")
#prints "The color purple is a great color!"
Here's why you see this error message: "Bummer: : Hmm...I answered the prompt with 'Red' but that's not what was in the variable favorite_color"
When you click "check work," the challenge is going to respond to your code.
It will see the question "What is your favorite color?" and respond "Red." Then it checks your print statement to see if it prints "The color red is a great color!"
In your second line of code, you set the favorite_color variable to purple.
favorite_color =input("What is your favorite color?")
#prompts user to enter their favorite color.
#whatever the user enters/inputs, that will be stored in the favorite_color variable.
favorite_color = "purple"
#but now, you set favorite_color to purple. Remember that Python reads the code one line at a time.
#It was whatever the user inputted, but now it's purple.
print("The color", favorite_color, "is a great color!")
#prints "The color purple is a great color!"
Let me know if you need more help!