@@ -33,23 +33,28 @@ class Laptop:
3333]
3434
3535
36- # Get the person's name
3736name = input ("What is your name? " )
3837
39-
40- # Get and convert age
4138try :
4239 age = int (input ("What is your age? " ))
4340except ValueError :
4441 print ("Age must be a number." , file = sys .stderr )
4542 sys .exit (1 )
4643
4744
48- # Get and convert operating system
45+ print ("Available operating systems:" )
46+ for os in OperatingSystem :
47+ print (os .value )
48+
4949try :
50- os_input = input ("What is your preferred operating system? " )
51- operating_system = OperatingSystem (os_input )
52- except ValueError :
50+ os_input = input ("What is your preferred operating system? " ).strip ().lower ()
51+
52+ operating_system = next (
53+ os for os in OperatingSystem
54+ if os .value .lower () == os_input
55+ )
56+
57+ except StopIteration :
5358 print ("Invalid operating system." , file = sys .stderr )
5459 sys .exit (1 )
5560
@@ -61,21 +66,18 @@ class Laptop:
6166)
6267
6368
64- # Count laptops with the person's preferred OS
6569number_available = sum (
6670 laptop .operating_system == person .preferred_operating_system
6771 for laptop in laptops
6872)
6973
70-
7174print (
7275 f"We have { number_available } laptop(s) with "
7376 f"{ person .preferred_operating_system .value } ."
7477)
7578
7679
77- # Find the operating system with the most laptops
78- counts = {}
80+ counts : dict [OperatingSystem , int ] = {}
7981
8082for os in OperatingSystem :
8183 counts [os ] = sum (
@@ -86,7 +88,6 @@ class Laptop:
8688
8789most_available_os = max (counts , key = counts .get )
8890
89-
9091if most_available_os != person .preferred_operating_system :
9192 if counts [most_available_os ] > number_available :
9293 print (
0 commit comments