Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Question
#1
First of all, I am new here so I am sorry if I am posting in the wrong place, and I would appreciate a link to the write place so I can perform correctly in the future.

I am learning python and have bought a book but I am confused about the 'input' command. In the book it has the code:
name = input("Hi, what's your name? ")
, but when I run this and enter any response (in this case the name Sam) I get the error:
Traceback (most recent call last):
  File "/home/pi/Desktop/Newseession.py", line 1, in <module>
    name = input("Hi, what is your name? ")
  File "<string>", line 1, in <module>
NameError: name 'Sam' is not defined
Am I missing something? Thank you for any help.
Reply
#2
this code is python3 and you are running it with python2
read https://python-forum.io/Thread-Python3-2...-raw-input

you should be using python3 as python2 support ended january 1st
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Feb-27-2020, 07:51 PM)Lighaldr Wrote: First of all, I am new here so I am sorry if I am posting in the wrong place, and I would appreciate a link to the write place so I can perform correctly in the future.

I am learning python and have bought a book but I am confused about the 'input' command. In the book it has the code:
name = input("Hi, what's your name? ")
, but when I run this and enter any response (in this case the name Sam) I get the error:
Traceback (most recent call last):
  File "https://mydataprovider.com/sites/", line 1, in <module>
    name = input("Hi, what is your name? ")
  File "<string>", line 1, in <module>
NameError: name 'Sam' is not defined
Am I missing something? Thank you for any help.

Thanks
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020