8/11


#1

This is my code:

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
   print original
word = original.lower()
first = word[0]

else:
  print 'empty'

This is the error:

File “python”, line 10
else:
^
SyntaxError: invalid syntax

It also says: Did you create a variable called word?

What am I doing wrong? Thanks.


#2

I would pay more attention to the syntax error then codecademy’s error message

else has to be after a an if condition (or elif), which its currently not. Currently its after a line where first variable is defined.


#3

Thank you. I think I was confuse by the instructions:
Inside your if statement: create…
And I didn’t consider “else” as part of the if condition.

Now it works. Thank you for your help.


#4

nesting is important for the flow of your program

its not part of the if condition, but if condition do something, else do something different. if, elif and else belong together/are related, but i wouldn’t define/describe it as part of


#5

Now it is more clear for me. Thanks!


#6

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