File tree Expand file tree Collapse file tree 1 file changed +22
-20
lines changed
Expand file tree Collapse file tree 1 file changed +22
-20
lines changed Original file line number Diff line number Diff line change @@ -50,32 +50,34 @@ def count_laptops_by_os(laptops: List[Laptop]) -> dict:
5050
5151def main ():
5252 # --- Input name ---
53- name = input ("Enter your name: " ).strip ()
54- if not name :
53+ while True :
54+ name = input ("Enter your name: " ).strip ()
55+ if name :
56+ break
5557 print ("Error: Name cannot be empty." , file = sys .stderr )
56- sys .exit (1 )
5758
5859 # --- Input age ---
59- age_input = input ("Enter your age: " ).strip ()
60- try :
61- age = int (age_input )
62- if age <= 0 :
63- raise ValueError ()
64- except ValueError :
65- print ("Error: Age must be a positive integer." , file = sys .stderr )
66- sys .exit (1 )
60+ while True :
61+ age_input = input ("Enter your age: " ).strip ()
62+ try :
63+ age = int (age_input )
64+ if age <= 0 :
65+ raise ValueError ()
66+ break
67+ except ValueError :
68+ print ("Error: Age must be a positive integer." , file = sys .stderr )
6769
6870 # --- Input preferred OS ---
69- print ("Choose preferred operating system:" )
70- for os in OperatingSystem :
71- print (f"- { os .value } " )
72- os_input = input ("Enter OS: " ).strip ()
73-
74- try :
75- preferred_os = OperatingSystem (os_input )
76- except ValueError :
71+ os_values = [os .value for os in OperatingSystem ]
72+ while True :
73+ print ("Choose preferred operating system:" )
74+ for os in OperatingSystem :
75+ print (f"- { os .value } " )
76+ os_input = input ("Enter OS: " ).strip ()
77+ if os_input in os_values :
78+ preferred_os = OperatingSystem (os_input )
79+ break
7780 print ("Error: Invalid operating system." , file = sys .stderr )
78- sys .exit (1 )
7981
8082 # --- Create Person ---
8183 new_person = Person (name = name , age = age , preferred_operating_system = preferred_os )
You can’t perform that action at this time.
0 commit comments