Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Meet Python Using Input

Ivet Achieng
Ivet Achieng
253 Points

why is red the variable being outputted when purple was my input?

I am confused

using_input.py
favorite_color =input("What is your favorite color?")
favorite_color = "purple"
print("The color", favorite_color, "is a great color!")

2 Answers

Hello 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,086 Points

Hi 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!