Trouble with Word Up!


For some reason my code is getting the error message, "Did you create a variable called word?"
I did, can someone please tell me what I did wrong?

pyg = 'ay'

original = raw_input('Enter a word:')

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


Hi @arrayninja11078 ,

Your posted code handles user input as it should. See what happens if you enter a valid word.

Codecademy checks to make sure that a variable named word has been defined, and that it has been assigned a lowercase conversion of the string referred to by original. If you enter a number or an empty string, the if block is skipped and the else block executes instead. Then, Codecademy issues a message, because word has not been defined.

In reality, you don't need for the variable, word, to get assigned a value when the user enters invalid input, because the only task that needs to be done is to output the string, 'empty'. So, test your code to make sure that it does what you want for both invalid and valid input, without being concerned about Codecademy's message. Finally, to pass and go on to the next exercise, enter a valid word.


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