name error "name"is not defined - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: name error "name"is not defined (/thread-28642.html) |
name error "name"is not defined - MaartenRo - Jul-28-2020 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: 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))) RE: name error "name"is not defined - bowlofred - Jul-28-2020 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 definedBecause you have not used python tags, it is difficult to see the indentation of your code. |