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 trialAlex Nassar
Python Web Development Techdegree Student 140 PointsPython 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!"
favorite_color = input("What is your favorite color? ")
print("Blue", "favorite_color")
if favorite_color == "blue":
print("you must love the sky!")
9 Answers
Johnstone Okoth
Courses Plus Student 6,316 PointsHi 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
348 PointsTake 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!")
Hong Sen Du
3,153 PointsUnlike 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
Python Web Development Techdegree Student 11,501 PointsYou 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
10,825 PointsWell, 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!")
Johnstone Okoth
Courses Plus Student 6,316 Pointsfavorite_color = input("What is your favorite color? ")
if favorite_color == "blue": print("you must love the sky!")
Perfect Tinotenda Mashingaidze
5,070 Pointsfavorite_color = input("What is your favorite color? ")
if favorite_color == "blue":
print("you must love the sky!")
Robert Rydlewski
3,828 PointsMy code doesn't work? How come?
favorite_color = input("What is your favorite color? ")
if favorite_color == "blue":
print("You must love the sky!")
Alan Babiarz
5,740 PointsOn 3rd line of your code, you need to make 2 spaces, then it works :)
Jose Mendoza
547 Pointsthis 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!"))