-1

I have a virtual machine CentOS Linux release 7.6.1810, I have installed python2 and I have the below python script:

 #!/bin/python2

 name = input('Please insert your name: ')
 age = input('Please insert your age: ')

 age = eval(age)

When I execute the script I'm getting the below standard output and standard error:

 [rogeliovs@hostname ~]$ python ./helloworld.py
 Please insert your name: rogelio
 Traceback (most recent call last):
    File "./helloworld.py", line 7, in <module>
       name = input('Please insert your name: ')
    File "<string>", line 1, in <module>
 NameError: name 'rogelio' is not defined
 [rogeliovs@hostname ~]$

Why I' getting that error ??????

  • If you are only just learning Python, you should definitely be targeting the currently recommended and supported version of the language, which is Python 3. By the original timeline, Python 2 would have reached its end of life almost a year ago, though it's on extended life support for a short while still. Saner input handling is one of the important changes in version 3. – tripleee Feb 25 '19 at 06:03

1 Answers1

2

Use raw_input() instead input()

Mahrez BenHamad
  • 1,791
  • 1
  • 15
  • 21