Python Forum
NameError: name '' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError: name '' is not defined
#1
Hi, I'm new to python. I've coded this to check whether an inputted name is between 3 and 10 letters and to ask the user whether they want to change it or not if it is. However, when I try to run it I get the error: 

File "/Users/archie/Downloads/namecheck/namecheck.py", line 11, in <module>
name = input("What's your name? ")
File "<string>", line 1, in <module>

NameError: name 'test' is not defined

There's probably an easy solution for this, but I am really confused as I can't see anything visibly wrong with the code. Can anybody help me? I am running the code in Wingide Pro v6.1.2-1.

namework = 0
while namework == 0:
    name = input("What's your name? ")
    if len(name) > 10:
        ncwork = 0
        while ncwork == 0:
            ncheck = input("Are you sure " + name + " is your name? Most names have between 3 and 10 characters. YES or NO ")
            ncheck = ncheck.lower()
            if ncheck == "yes":
                ncwork = 1
                namework = 1
            elif ncheck == "no":
                ncwork=1
    elif len(name) < 3:
        ncwork = 0
        while ncwork == 0:
            ncheck = input("Are you sure " + name + " is your name? Most names have between 3 and 10 characters. YES or NO ")
            ncheck = ncheck.lower()
            if ncheck == "yes":
                ncwork=1
                namework=1
            elif ncheck == "no":
                ncwork=1
    else:
        namework=1
Reply
#2
This looks like you are running Python 2.7 or earlier, the code you have is written for Python 3.0 or later. The behavior of the input function changed in Python 3.0.

You want to learn on 3.0 or later, but you need to make sure you are running your code in the appropriate version.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm getting a NameError: ...not defined. vonArre 2 260 Mar-24-2024, 10:25 PM
Last Post: vonArre
  Getting NameError for a function that is defined JonWayn 2 1,091 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,873 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  [split] NameError: name 'csvwriter' is not defined. Did you mean: 'writer'? cathy12 4 3,302 Sep-01-2022, 07:41 PM
Last Post: deanhystad
  NameError: name ‘app_ctrl’ is not defined 3lnyn0 0 1,503 Jul-04-2022, 08:08 PM
Last Post: 3lnyn0
  NameError: name 'hash_value_x_t' is not defined Anldra12 5 1,911 May-13-2022, 03:37 PM
Last Post: deanhystad
  NameError: name 'cross_validation' is not defined tmhsa 6 13,331 Jan-17-2022, 09:53 PM
Last Post: TropicalHeat
  NameError: name “x” is not defined ... even though x is defined campjaybellson 7 14,938 Oct-20-2021, 05:39 PM
Last Post: deanhystad
  NameError: name 'Particle' is not defined in Pygame drunkenneo 4 3,358 Aug-15-2021, 06:12 PM
Last Post: bowlofred
  NameError: name 'u1' is not defined (on parser code Python) Melcu54 1 2,873 Jul-26-2021, 04:36 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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