Skip to content

Commit f019d5d

Browse files
committed
fix; improve validation for Perferred_OS
1 parent 9903868 commit f019d5d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

Perp-exercises/enum8.1.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,20 @@ def read_operating_system() -> OperatingSystem:
9797
1.Ubuntu
9898
2,Arch Linux
9999
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]: "))
100+
101+
while True:
102+
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+
103109
os_map: dict[int, OperatingSystem] = {
104-
1: OperatingSystem.UBUNTU,
105-
2: OperatingSystem.ARCH,
106-
3: OperatingSystem.MACOS,
107-
}
110+
1: OperatingSystem.UBUNTU,
111+
2: OperatingSystem.ARCH,
112+
3: OperatingSystem.MACOS,
113+
}
108114
return os_map[choice]
109115

110116

0 commit comments

Comments
 (0)