-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path@unique_github.py
More file actions
34 lines (29 loc) · 965 Bytes
/
@unique_github.py
File metadata and controls
34 lines (29 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from enum import Enum, unique
@unique
class IceCreamFlavor(Enum):
VANILLA = 1
CHOCOLATE = 2
STRAWBERRY = 3
MINT = 4
COFFEE = 5
# Error line:
#ANOTHER_VANILLA = 1 # ❌ This would throw an error because the value is 1 again!
def display_flavors():
print("\n🍨 Available Ice Cream Flavors:\n")
for flavor in IceCreamFlavor:
print(f"• {flavor.name.title():<12} ➜ Code: {flavor.value}")
def get_flavor_by_value(value):
try:
flavor = IceCreamFlavor(value)
print(f"\n✅ You selected: {flavor.name.title()}")
except ValueError:
print("\n⚠️ No flavor found with that code!")
def main():
display_flavors()
val = input("\n🔢 Enter the code of your favorite flavor: ").strip()
if val.isdigit():
get_flavor_by_value(int(val))
else:
print("⚠️ Please enter a valid number.")
if __name__ == "__main__":
main()