0

I am writing a simple input and I keep getting an error. Fir example if I type in 'Eagle' it get name error eagle is not defined. Why is this?

print("The new word?")
newword = input()
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • 8
    possible duplicate of [Python input() error - NameError: name '...' is not defined](http://stackoverflow.com/questions/21122540/python-input-error-nameerror-name-is-not-defined) – Morgan Thrapp Sep 21 '15 at 15:48
  • Probably just as well it's a duplicate, as the answers so far are... not great. – jonrsharpe Sep 21 '15 at 16:12

1 Answers1

1

Use raw_input instead if you don't want to evaluate the expression supplied. By default python evaluates whatever you supply to input as python expression, raising the name error.

newword = raw_input('the new word')

Otherwise, if you are meant on using input, then you need to enclose your entry string in quotes. Then python would consider it a string eliminating the NameError. Supply 'Eagle' instead of Eagle. Moreover, its better to supply the prompt string in input parameters i.e.

newword = input('The new word')

#supply 'Eagle' (in quotes)
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
hspandher
  • 15,934
  • 2
  • 32
  • 45