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

name = input ("whats your name? ")

name = input ("whats your name? ")
if name == "sub":
  print(name + " is an ax and he/she's OK!")
  else:
    print(name + " sleeps all night and " + name + " works all day and eats chicken!")

Hi Arvin,

What was your question?

oh the error is not displayed here but got this synthax error and couldn't run the name.py

1 Answer

You have your else statement indented but it should be lined up with the corresponding if statement.

Your else statement and the subsequent print should be un-indented 1 level

Thanks! I had no idea that indentation can interfere with running a function.

With that being said, it still gives me the same error!

Yes, in python indentation is very important because that's what decides which lines of code belong to which blocks.

Can you post the error you're getting as well as the current code you're trying? Also, what part of the course are you on right now?

>>> python zech.py                                                                               
  File "<stdin>", line 1                                                                         
    python zech.py                                                                               
              ^                                                                                  
SyntaxError: invalid syntax  

The code:

name = input ("whats your name? ")
if name == "sub":
  print(name + " is a ashiy and he/she's OK!")
else:
print(name + " sleeps all night and " + name + " works all day and eats chicken!")

Thanks for the reply!

Your print statement that's part of the else should be indented one level.

It looks like you're trying to run your python command from within the python environment.

>>> python zech.py

You should be at your normal command prompt when entering python zech.py

Exit out of the python shell first if you're in that then you can go ahead and run your python command to run your file.

It looks like you ran python first from the command line giving you the prompt

>>>

Then you tried to run the python command again.

That makes so much sense now that you said it! it runs smoothly

Glad you got it working!