Why does this code not work


#1

According to codecademy, the correct python if/else statement goes like this

if statement : 
       print "the statement is true"
else:
       print "the statement is false"

and it works, but when i do this:

print 'Welcome to the Pig Latin Translator!'
original = raw_input("Enter a word:")
if len(original) > 0 :
    print original
    else:
print "empty"

it says the else is a syntax error?
answers will be much appreciated :slight_smile:


#2

Try something like this.

print 'Welcome to the Pig Latin Translator!'

name = raw_input("What's your name?")
original = raw_input 

maybe = "maybe write something"
if len(name) > 0 and name.isalpha():
print name 
    else:
    print maybe

If you have any questions or not getting some of the code above flick me a message and I will explain .
If this solved your problem please mark this reply as the solution, thanks :slight_smile:


#3

i got the code right, i was just stumped on why the else wasnt working


#4

It's due to the indentation. It should not be indented.


#5

oh, will remeber that :smile:


#6

Indentation, mate. You have to take care of those whitespaces always :wink:

if len(name) > 0 and name.isalpha():
    print name 
else:
    print maybe

#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.