Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError with simple code
#1
Hi, This is my first post on the forum.

I'm currently learning the basics of Python from a 2014 copy of "Idiot's Guides: Beginning Programming". I'm using Python 3.5.3 on Mac OS.

The book is using examples from Python 3.3.

One of the first examples in the book is a simple question and response piece of code (below).

input_var = input("What is your name? ")
print("Hello " + input_var)
I've saved that as a .py file and then gone to Terminal and changed the directory to the folder I have the file saved in.

I then open it up in Terminal and this happens...

python ch3_1.py
What is your name? Daniel
Traceback (most recent call last):
     File "ch3_1.py", line 1, in <module>
          input_var = input("What is your name? ")
     File "<string>", line 1, in <module>
NameError: name 'Daniel' is not defined
Why is this happening? I thought it should look something like this...

Output:
python ch3_1.py What is your name? Daniel Hello Daniel
Thanks in advance for any help or suggestions. Cheers, Dan :)

Just quick update. I was playing around with it and for some reason the code works when I type...

python ch3_1.py
What is your name? "Daniel"
Hello Daniel

Is that normal? I thought you didn't need to use quotation marks when responding only in the code?
Reply


Messages In This Thread
NameError with simple code - by DanielBrasher - Feb-18-2017, 12:22 AM
RE: NameError with simple code - by wavic - Feb-18-2017, 01:06 AM
RE: NameError with simple code - by Larz60+ - Feb-18-2017, 01:21 AM
RE: NameError with simple code - by DanielBrasher - Feb-18-2017, 01:52 AM
RE: NameError with simple code - by Ofnuts - Feb-18-2017, 10:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 455 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 578 Nov-07-2023, 04:32 PM
Last Post: snippsat
  help me simple code result min and max number abrahimusmaximus 2 998 Nov-12-2022, 07:52 AM
Last Post: buran
  Simple encoding code ebolisa 3 1,558 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,886 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Simple code question about lambda and tuples JasPyt 7 3,508 Oct-04-2021, 05:18 PM
Last Post: snippsat
  NameError issue with daughter's newb code MrGonk 2 1,539 Sep-16-2021, 01:29 PM
Last Post: BashBedlam
  My simple code don't works !! Nabi666 1 1,660 Sep-06-2021, 12:10 PM
Last Post: jefsummers
  NameError: name 'u1' is not defined (on parser code Python) Melcu54 1 2,966 Jul-26-2021, 04:36 PM
Last Post: snippsat
Sad SyntaxError: from simple python example file from mind-monitor code (muse 2) warmcupoftea 4 2,964 Jul-16-2021, 02:51 PM
Last Post: warmcupoftea

Forum Jump:

User Panel Messages

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