Showing posts with label common errors. Show all posts
Showing posts with label common errors. Show all posts

Saturday, July 5, 2014

Error while using input() function

 Error while using input() function :---

#!/usr/bin/python
print ('Hello! What is your name?')
myName = input()


 Output:-
 Hello world!
What is your name?
Aman
Traceback (most recent call last):
File "C:/Python24/game.py", line 3, in <module>
myName = input()
File "<string>", line 1, in <module>
NameError: name 'Aman' is not defined



...then this means you are running the program with Python 2, instead of Python 3.

The input() and raw_input() Functions
In Python 2, the function to get input from the keyboard is raw_input(). In Python 3, the input() function does this. You can simply rename the function wherever it appears in your code.
>>> # Python 2
>>> name = raw_input()
>>> # Python 3
>>> name = input()

#!/usr/bin/python
print ('Hello! What is your name?')
myName = raw_input()