@@ -73,26 +73,28 @@ def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]
7373# Get user input as strings first (raw input)
7474name = input ("Enter your name: " )
7575age_str = input ("Enter your age: " )
76- os_str = input ("Enter preferred OS: " )
76+ print ("Available operating systems: Ubuntu, macOS, Arch Linux" )
77+ os_str = input ("Enter your preferred OS (Ubuntu, macOS, or Arch Linux): " )
7778
7879# --------------------------------------------------------------------
7980# INPUT VALIDATION AND CONVERSION
8081# --------------------------------------------------------------------
8182
8283# Convert age from string to integer with error handling
8384# Output to stderr as per requirements, exit with non-zero code
84- try :
85- age = int (age_str )
86- except ValueError :
87-
88- print (f"Error: { age_str } is not a valid age" , file = sys .stderr )
89- sys .exit (1 )
85+ while True :
86+ age_str = input ("Enter your age: " )
87+ try :
88+ age = int (age_str )
89+ break
90+ except ValueError :
91+ print (f"Error: { age_str } is not a valid age. Please enter a number." )
9092
9193# Convert OS string to enum with error handling
9294try :
9395 os = OperatingSystem (os_str )
9496except ValueError :
95- print (f"Error: '{ os_str } ' is not a valid OS. Choose : Ubuntu, macOS, Arch Linux" , file = sys .stderr )
97+ print (f"Error: '{ os_str } ' is not a valid OS. Valid options are : Ubuntu, macOS, Arch Linux" , file = sys .stderr )
9698 sys .exit (1 )
9799
98100
0 commit comments