@@ -56,7 +56,11 @@ def chose_alternative_laptops(laptops: List[Laptop], person: Person) -> Dict[Ope
5656 if count > number_possible_laptops :
5757 alternative_laptops [eachOS ] = count
5858 if len (alternative_laptops ) != 0 :
59- print (f"There is an operating system that has more laptops available.If you’re willing to accept them, there is a list: { alternative_laptops } ." )
59+ print ("There is an operating system that has more laptops available.If you’re willing to accept them, there is a list:" )
60+ list_os = []
61+ for os , count in alternative_laptops .items ():
62+ list_os .append (f"{ os .value } : { count } " )
63+ print (" ," .join (list_os ))
6064 return alternative_laptops
6165 else :
6266 print ("There is not an operating system that has more laptops available." )
@@ -81,9 +85,14 @@ def chose_alternative_laptops(laptops: List[Laptop], person: Person) -> Dict[Ope
8185
8286available_os = [os .value for os in OperatingSystem ]
8387print ("Available OSs are: " , "," .join (available_os ))
84- user_operating_system = input ("Type operating system: " ).strip ()
85- if user_operating_system not in available_os :
86- print (f"Error, { user_operating_system } is not in available list\n "
88+ while True :
89+ user_operating_system = input ("Type operating system: " ).strip ()
90+ try :
91+ if user_operating_system not in available_os :
92+ raise ValueError
93+ break
94+ except ValueError :
95+ print (f"Error, { user_operating_system } is not in available list\n "
8796 f"Available OSs are: { ',' .join (available_os )} " , file = sys .stderr )
8897 sys .exit (1 )
8998
@@ -99,7 +108,7 @@ def chose_alternative_laptops(laptops: List[Laptop], person: Person) -> Dict[Ope
99108 Laptop (id = 4 , manufacturer = "Apple" , model = "macBook" , screen_size_in_inches = 13 , operating_system = OperatingSystem .MACOS ),
100109]
101110
102-
103111possible_laptops = count_possible_laptops (laptops , user )
104112print (f"Possible laptops for { user_name } : { possible_laptops } " )
105113alternative_laptops = chose_alternative_laptops (laptops , user )
114+
0 commit comments