What am I doing wrong?


#1

pyg = ‘ay’
new_word = word + first + pyg
new_word = new_word[1:]
original = raw_input(‘Enter a word:’)

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

I’m getting an error stating that:
Traceback (most recent call last): File “python”, line 2, in <module> NameError: name ‘word’ is not defined


#2

this code:

new_word = word + first + pyg
new_word = new_word[1:]

why did you place where you did? Are these the actions you want to take at that part of your program?


#3

It says:
On a new line after where you created the first variable:

Create a new variable called new_word and set it equal to the concatenation of word , first , and pyg .

My first variable is pyg that’s why I put it there


#4

but you didn’t create the new variable named new_word after where you created first variable, which is why i questioned it


#5

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
else:
print ‘empty’


#6

Serious question, How come the positioning matter? How come it has to be within the IF statement?


#7

the program runs from top to bottom, so the order in which you place the code matters.


#8

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