0

I have been learning Python and have encountered an error displaying the result of using input. My mistake still eludes even after: Python Input, Py Docs and many others.

My expected output would be what the user types but instead I get a syntax error on line 7 test_two = input...

# test program

test_one = 'bob'
print (test_one)
print test_one

test_two = input('What is your city? ')

print "City: ", test_two

I am unable to spot what is different to many of the examples I have seen. It seems like its doing an eval on the entered text?

 Traceback (most recent call last):   
   File ".\test.py", line 7, in <module>
     test_two = input('What is your city?')   
   File "<string>", line 1, in <module> 
 NameError: name 'Paris' is not defined
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
miltonb
  • 6,905
  • 8
  • 45
  • 55
  • 1
    Use `raw_input`. `input` perfoms an `eval` on whatever text is input. `raw_input` is renamed to `input` in python 3. – Paul Rooney Nov 20 '17 at 08:23
  • 1
    Because `input()` uses `eval()` to execute the entered text. Use `raw_input()` instead. – Martijn Pieters Nov 20 '17 at 08:24
  • Interesting. I started with ``raw_input` however when running under debugger on Microsoft vscode, the input would be multiple lines and would never stop. Maybe there is a problem with the Extension. I will investigate. – miltonb Nov 20 '17 at 08:34

0 Answers0