Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6960

Python • NameError: name 'Color' is not defined

$
0
0
Anyone has tested these code on https://docs.python.org/3/tutorial/controlflow.html ?

Code:

from enum import Enumclass Color(Enum):    RED = 'red'    GREEN = 'green'    BLUE = 'blue'color = Color(input("Enter your choice of 'red', 'blue' or 'green': "))match color:    case Color.RED:        print("I see red!")    case Color.GREEN:        print("Grass is green")    case Color.BLUE:        print("I'm feeling the blues :(")
if there were no "Tab" before "color...", it would prompt:

Code:

  File "<stdin>", line 5    color = Color(input("Enter your choice of 'red', 'blue' or 'green': "))    ^^^^^SyntaxError: invalid syntax
if one "Tab" added, it would prompt:

Code:

Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "<stdin>", line 5, in ColorNameError: name 'Color' is not defined

Statistics: Posted by MianQi2019 — Mon Nov 10, 2025 5:21 am — Replies 1 — Views 48



Viewing all articles
Browse latest Browse all 6960

Trending Articles