0

I am learning python basics and when using the input function i am getting certain errors.

What is your name? Michael
Traceback (most recent call last):
File "new.py", line 1, in <module>
name = input("What is your name? ")
File "<string>", line 1, in <module>
NameError: name 'Michael' is not defined

I've tried deleting and reinstalling all packages and I cannot figure out what is the issue with this.

The program is as follows.

name = input("What is your name? ")
print(name)

Not sure what i'm doing wrong. Also im using python version 3.6.5 on Visual Studio Code.

  • 2
    You must be using Python 2, not 3. Use `raw_input` in 2. `input` has `eval` behavior in 2. It's trying to interpret the input as a variable name. – Carcigenicate Jan 23 '19 at 22:40
  • 2
    Possible duplicate of [input() error - NameError: name '...' is not defined](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – Carcigenicate Jan 23 '19 at 22:41
  • @Carcigenicate seems to be the same. For some reason i cannot uninstall python 2.7. VS code says im using 3.6.5 but clearly im not because the issues are the same as the other persons problem. Any way to get it to uninstall that version? Or just be sure that im using the right version, becuase i think it might be overlapping them. –  Jan 23 '19 at 22:53
  • I've never used VS to write Python, so I'm not sure how it handles different versions. If you poke around the settings, there may be an option to pick what version of interpreter is used. – Carcigenicate Jan 23 '19 at 22:54
  • @Carcigenicate ive tried it. Specifically chose and removed version 2.7 from VS code. Still throwing the error. What did u use to write python? –  Jan 23 '19 at 22:56
  • You may need to restart the IDE/computer after removing 2. And I use IDLE the odd time I write Python (Python's not my main language). – Carcigenicate Jan 23 '19 at 22:59
  • Try running `import platform print(platform.python_version())` to see what version you're on. – Carcigenicate Jan 23 '19 at 23:01
  • @Carcigenicate You are right of course. Python Version is stuck at 2.7 even after restarting. Just going to uninstall all files and redownload it. –  Jan 23 '19 at 23:07
  • Sorry I couldn't help further. My only experience with VS is when I used to write Typescript, and that was only for like 2 months. – Carcigenicate Jan 23 '19 at 23:14
  • @Carcigenicate all good, think its a bug with vsc. switched ide and it works fine now. Thanks for the help. –  Jan 23 '19 at 23:30

1 Answers1

0

Run the code in Terminal of VSCode. When you run the code using ctrl + alt + n it shows only static output, you can't give dynamic output there.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
VAMSHI P V
  • 11
  • 1