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 (Retired) Ins & Outs Ins & Outs

Phillip Shakesby
Phillip Shakesby
1,009 Points

my code is not working on create a variable with name in it challenge

help me understand why my code is not working on create a variable with name in it challenge

my code is below:

name = input("What's your name?")

if name == "Phillip": print(name + " is cool ") else: print (name + " is a dork and " + name + " smells funny! ")

2 Answers

Hello Phillip,

The if statement you have needs to be properly indented for it to work. Alternatively, there is a shorthand version that can be used. The two ways you can write them are like this:

name = input("What's your name?")

# this is a proper "if" statement
if name == "Phillip":
    print(name + " is cool ")
else:
    print (name + " is a dork and " + name + " smells funny! ")

# this is the shorthand version
print(name + " is cool ") if name == "Phillip" else print (name + " is a dork and " + name + " smells funny! ")

Hopefully this helps solve your problem.

Stone Preston
Stone Preston
42,016 Points

task 1 states: Create a variable named name with your name in it.

you dont use input, just set the value of the variable:

name = "stone"

also, you dont need the if else block. you only need to do what the challenge task asks. no more. no less. The challenges are very picky and usually you wont pass if you do something it doesnt ask for.

all you need is to set the value of a variable called name:

name = "stone"