Prompting for user input in Python 2



examples/basics/prompt2.py
from __future__ import print_function

def main():
    print("We have a question!")
    name = raw_input('Your name: ')
    print('Hello', name, ', how are you?')
    print('Hello ' + name + ', how are you?')

main()

/usr/bin/python2 prompt2.py

We have a question!
Your name: Foo Bar
Hello Foo Bar , how are you?
Hello Foo Bar, how are you?

What happens if you run this with Python 3 ?


/usr/bin/python3 prompt2.py


We have a question!
Traceback (most recent call last):
  File "prompt2.py", line 7, in <module>
    main()
  File "prompt2.py", line 4, in main
    name = raw_input('Your name: ')
NameError: name 'raw_input' is not defined