Why the input function fails in returning result by a basic script?

Dear All:
I am learning the ‘input’ fuction by follow the intro book to write the script in command window, but it returns back a red message. It is weird to me as I just copy the script line from book to test, but without getting back a same answer as it is written in the book.
Here I type the sentence ‘CHUCK’ as written in the book.
Below it the sampe and what I typed in Pyton in rhino.
Could any professor tell me why this happens? It is very simple line that I didn’t expect to meet such problem…
I tested this command this time,

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

The error is

Message: name 'CHUCK' is not defined

Traceback:
  line 1, in <module>, "C:\Users\Lenovo\AppData\Local\Temp\TempScript.py"
  line 1, in <module>, "<string>"

Thanks in advance!

Please do not post pictures of text.
Copy the text from the app an use the pre-formatted text feature that is the button </>.

I cannot read the blurry error.

1 Like

Hi, Barry
Thanks for your suggestions!
Here are the problem, when I type ‘CHUCK’ when it requires an input, it show below:

MY CODE:

input('What is your name?')
print(name)

THE ERROR MESG IS HERE:

Message: name 'CHUCK' is not defined

Traceback:
  line 1, in <module>, "C:\Users\Lenovo\AppData\Local\Temp\TempScript.py"
  line 1, in <module>, "<string>"

What version of Python are you using?
In Python 3 this should indeed be simple and no problem, but in Python 2 and before input worked differently and raw_input did what input does nowadays.

Also, please copy your code instead of rewriting it, you probably forgot to start the first line with "name = ".
If you execute this as you’ve written it, you get name 'name' is not defined

You are using Python version 2.

You should not use Python 2, it is old and obsolete.

Upgrade to Python 3. You should use 3.10 or 3.11 if you can, but certainly 3.8 as a minimum.

If you are stuck using Python 2, you should:

  • replace input with raw_input instead;
  • use a Python 2 tutorial, not a Python 3 tutorial;
  • or be prepared to have a very bad time, with many annoying errors like this.

Thanks Alvert!
My python is 3.11,
also, I edited in first post with 'name = ', emmm, seem not help at alll
I assume it maybe version problem?

name = input('What is your name?')
print(name)
Message: name 'chuck' is not defined

Traceback:
  line 1, in <module>, "C:\Users\Lenovo\AppData\Local\Temp\TempScript.py"
  line 1, in <module>, "<string>"

Hi, Steven
Thanks!
I think you are right, the most probable issue should be version.
Let me update and have a try.
:fist:

2 posts were split to a new topic: How to provide input to the input function?