feat: Added several demo programs

This commit is contained in:
xpk
2025-11-28 08:29:28 +08:00
parent 9d044c20c9
commit 3baa1996c2
4 changed files with 104 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
r"""
Documentation
License: This program is released under the MIT License
"""
# Imports
from enum import Enum
class Color(Enum):
RED = '#FF0000'
GREEN = '#00FF00'
BLUE = '#0000FF'
# function which uses the Enum
def paint_wall(color: Color) -> None:
match color:
case Color.RED:
print("Red wall, are you serious?")
case Color.GREEN:
print("Green wall, very foresty.")
case Color.BLUE:
print("Blue wall, I like it.")
case _:
print("Other colors are not preferred.")
# Main function
def main() -> None:
# Check Enum name and value
print(f"Enum: {Color.RED} Name: {Color.RED.name} Value: {Color.RED.value}")
# function that uses Enum
paint_wall(Color.RED)
# print all Enum values
print([x.value for x in Color])
# check if value is a member of the Enum, kind of pointless as IDE will report the problem ahead
# print(Color.BLACK in Color)
# Call main function
if __name__ == '__main__':
main()