Python Forum
name error "name"is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
name error "name"is not defined

I am doing an exercise but somehow my code doesn't work. It should ask for a colorname and when the user types red, orange, yellow, green or blue it should state that the color is in the list.

I get this error message when running the program:

while str.upper(ColorSelect) != "STOP": NameError: name 'ColorSelect' is not defined
What am i doing wrong?

Thanks in advance for the help!

Colors = ["Rood", "Oranje", "Geel", "Groen", "Blauw"]

Colorselect = ""

while str.upper(ColorSelect) != "STOP":
   ColorSelect = input("Typ een kleurnaam: ")
   if (Colors.count(ColorSelect) >= 1):
      print("De kleur staat in een lijst!")
   elif (str.upper(ColorSelect) !="STOP"):
      print("De kleur staat niet in een lijst.")

I have another problem in this code: unexpected indent error before " aantal: ", ThisItem[1])

What is the error?
Any input is very much appreciated!

from collections import Counter

MyList = [1, 2, 3, 4, 1, 2, 3, 1, 2, 1, 5]
ListCount = Counter(MyList)


for thisItem in ListCount.items():
   print("Item: ", ThisItem[1])
         " aantal: ", ThisItem[1])
print("De waarde 1 verschijnt {0} keer."

Please use "python" tags for code, not "quote" tags.

Python variables are case sensitive. Different cases are different variables. You define one variable and then try to access a different one.

>>> Colorselect = ""
>>> print(ColorSelect)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ColorSelect' is not defined
Because you have not used python tags, it is difficult to see the indentation of your code.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 733 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Error when refering to class defined in 'main' in an imported module HeRo 2 835 Apr-13-2021, 07:22 PM
Last Post: HeRo
  Why does lambda throw 'name value_o is not defined' error? karabakh 3 885 Dec-14-2020, 05:45 PM
Last Post: karabakh
  Name Error: name 'Stockton' is not defined Pinokchu 3 1,102 Jun-13-2020, 02:48 PM
Last Post: Yoriz
  python library not defined in user defined function johnEmScott 2 1,088 May-30-2020, 04:14 AM
Last Post: DT2000
  error ,,name append is not defined'' Killdoz 1 2,157 May-24-2020, 06:23 PM
Last Post: bowlofred
  name error:name 'clf' is not defined saiankith 3 4,728 Mar-31-2020, 06:49 PM
Last Post: jefsummers
  Error: variable can not be defined julio2000 2 1,686 Feb-09-2020, 08:51 PM
Last Post: julio2000
  Getting the error like function not defined .. suggest correct code raghava 1 1,017 Feb-04-2020, 11:20 PM
Last Post: micseydel
  Error name 'A' not defined RavCOder 3 1,500 Sep-23-2019, 03:51 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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