Exercise 2.4 Ending up


#1


I did the right thing that the instructions was asking, but it says that I have an error that 'word' is not defined. What should i do? Heres the error that shows up on the console window:

Oops, try again. Your code did not run to end - see the console window for the error message. Traceback (most recent call last):
File "python", line 2, in
NameError: name 'word' is not defined


Heres my code:


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


Please help me


#2

Look at the line number the error message mentions
Have you defined it at that point? Are you using it before defining it? Can you do that?


#3

well, the instructions told me to add that in. And word should definitely be in there.


#4

Do you agree that you would need to define a variable before reading from it?

Look at where you read it, and where you define it. If you read before defining it, then execution will stop because you would be asking for something that cannot be carried out


#5

Well, this is the code when I first reset it:

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

And when I try to do the instructions correctly, it still gives me the error


#6

Could you perhaps reorder your actions so that those which depend on others only come after those dependencies have been carried out?

Problem: using variable before having defined it
Solution: use it later, or define it earlier


#7

I probably could do that


#8

aaaaaaaaaaaand it did work


#9

what 's your final code?

i still failed....


#10

@textrunner10547 it was something like this:

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

but you have to switch the new_word to the bottom (i think or something else to the bottom)


#11

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