Python Forum

Full Version: name error "name"is not defined
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

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:

Error:
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)

print(ListCount)

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

      .format(ListCount.get(1)))
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.