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

Python Basics

Can somebody please explain what I did wrong? I am new and trying to get Python to finally click in my head.

The code to accept input for the favorite color has been provided for you. For this task, add a branch that checks if the favorite_color is equal to "blue". If it is indeed "blue" print out to the screen, "You must love the sky!"

branching.py
favorite_color = input("What is your favorite color?  ")
print("Blue", "favorite_color")
if favorite_color == "blue":
print("you must love the sky!")

9 Answers

Hi I hafavorite_color = input("What is your favorite color? ") if favorite_color == "blue": print("you must love the sky!")d the same mistake.How I solved it is to make sure the line 3 is pushed forward..

rnw98613
rnw98613
348 Points

Take care of indentation, it is strict about indentation in python, because they replaces the curly braces

favorite_color = input("What is your favorite color?  ")

if favorite_color == "blue":
  print("you must love the sky!")

Unlike in other languages, indentation of nested blocks in Python is required. Indentation in other languages is only "style", the set of standard conventions programmers use to make code easier to read and understand.

Brandon Oakes
seal-mask
.a{fill-rule:evenodd;}techdegree
Brandon Oakes
Python Web Development Techdegree Student 11,501 Points

You are very close my friend. First off, your code on line 2 is not needed.

   print("Blue", "favorite_color")

so after you git rid of that all you need to do is indent your print statement after your if statement shown below.

  favorite_color = input("What is your favorite color?  ")
  if favorite_color == "blue":
      print("you must love the sky!")

When using an if statement, you are an essence testing a condition. So here you are saying if the value for favorite_color is equal to (==) blue than perform . the desired code. You need to always make sure to indent the code you want to run under the conditional statement to make sure the code ONLY runs if the condition is true. Let me know if that makes sense

Tuan Phan
Tuan Phan
10,825 Points

Well, as the requirement of this task, it only asks you to print out the result if the favorite_color is "blue". So...you just need to print it out after checking it right.

favorite_color = input("What is your favorite color?  ")
if favorite_color == "blue":
print("you must love the sky!")

favorite_color = input("What is your favorite color? ")

if favorite_color == "blue": print("you must love the sky!")

favorite_color = input("What is your favorite color? ")

if favorite_color == "blue":

print("you must love the sky!")

Robert Rydlewski
Robert Rydlewski
3,828 Points

My code doesn't work? How come?

favorite_color = input("What is your favorite color? ") if favorite_color == "blue": print("You must love the sky!")

On 3rd line of your code, you need to make 2 spaces, then it works :)

this is my code but it does not work please help

favorite_color = input("What is your favorite color? ") if(favorite_color == "blue": print("you must love the sky!"))