There was an error while loading. Please reload this page.
1 parent 9903868 commit f019d5dCopy full SHA for f019d5d
1 file changed
Perp-exercises/enum8.1.py
@@ -97,14 +97,20 @@ def read_operating_system() -> OperatingSystem:
97
1.Ubuntu
98
2,Arch Linux
99
3.macOs""")
100
- choice: int = int(input("Enter Your choice[1-3]: "))
101
- while choice < 1 or choice > 3:
102
- choice = int(input("Enter Your choice[1-3]: "))
+
+ while True:
+ try:
103
+ choice = int(input("Enter Your choice[1-3]: "))
104
+ if 1 <= choice <= 3:
105
+ break
106
+ except ValueError:
107
+ print("please enter a valid number.")
108
109
os_map: dict[int, OperatingSystem] = {
- 1: OperatingSystem.UBUNTU,
- 2: OperatingSystem.ARCH,
- 3: OperatingSystem.MACOS,
- }
110
+ 1: OperatingSystem.UBUNTU,
111
+ 2: OperatingSystem.ARCH,
112
+ 3: OperatingSystem.MACOS,
113
+ }
114
return os_map[choice]
115
116
0 commit comments