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 Types and Branching Use an if

How do I ask to check if someone likes blue?

What if statement do I use?

branching.py
favorite_color = input("What is your favorite color?  ")
    favorite_color == "blue"
Print("You must love the sky")

2 Answers

Cooper Runstein
Cooper Runstein
11,850 Points

You need to test if favorite_color is blue:

if favorite_color == 'blue':
    print("You must love the sky")

Thank You for you help!

You would use what's called an IF conditional statement. In essence, it works just like in the English language. Eg: "If they have cakes at the store, I will get two." The if statement works when the condition given to it is true.

In your case, you would use the condition to see if the input variable is the same as the string "blue".

favorite_food = input ("what is your favorite food?")
    favorite_food = "pizza"
if favorite_food == "pizza"
    print("You must love the big jay pizzeria down the street.")

Remember, you're using a two equal signs (== ). The two equal signs checks if the two things beside it are equal. The one equal sign (=) just assigns the value on the right to the variable on the left (a=10).

Thank You for your help!