Pyglatin else statement


#1

i keep getting a syntax error ‘SyntaxError: invalid syntax’ from my else statement. am i missing something?

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 new_word
else:
print “empty”


#2

Can’t say. We are missing indentation on your code.


#3

Wouldn’t error call out indention if that was the case not syntax?


#4

Yes, that would be the case. Are those fancy quotes on "empty"? That will cause an error.


#5

I keep getting the same error: can’t for the life of me figure out why!

If i remove line:

print new_word

The code runs fine but doesn’t “translate”, and if I remove the else statement, the code runs fine but does not show any errors for if the input was empty/contains numbers.

Very strange! Let me know if you figure it out :slight_smile:


#6

I just tried again, and it’s working.

Here’s my 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 new_word
else:
print ‘empty’

Seems to be identical to yours so I’m not sure why it didn’t work: but keep trying! :slight_smile:


#7

Mine turned out to be an indention issue as suggested. I was only indented 2 spaces but needed 4.
Happy coding.