4. Check yourself syntax


#1



https://www.codecademy.com/en/courses/python-beginner-2W5v7/0/4?curriculum_id=4f89dab3d788890003000096#


Giving me a syntax error where my else is, but I'm not sure why?


The indentation looks the same as my if statement so it should run I thought


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


#2

Hi put this part

raw_input("Enter a word:")
original=raw_input()

Before the if and else statement then put It like that

original = raw_input("Enter a word:")

#3

It's still giving me the syntax error on "else", and it also said "did you accidentally delete the variable called original?" My code now looks like:

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


#4

Try this code:

pyg = 'ay'
original = raw_input('Enter a word: ')
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word [ 1 : len(new_word)]
print original
print new_word

Hope this helps.


#5

There are two mistakes that I would like to highlight, one is the raw_input thing is wrong, two, the else condition syntax is wrong. The correct should be something like this:

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

#6

I ended up figuring it out with your guys' help, thanks!


#7

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