1+ """
2+ Parent Class
3+ """
4+ class Laptop :
5+ def __init__ (self ):
6+ # minimum specs
7+ self .cpu = "i3 10th Gen"
8+ self .gpu = "MX 130"
9+ self .ram = "8 GB"
10+ self .display = "1080p"
11+ self .battery = "60 WHr"
12+ self .storage = "256 GB SSD"
13+
14+
15+ def setSpecifications (self ,specs :dict ):
16+ try :
17+ self .model = specs ["model" ]
18+ self .cpu = specs ["cpu" ]
19+ self .gpu = specs ["gpu" ]
20+ self .ram = specs ["ram" ]
21+ self .display = specs ["display" ]
22+ self .battery = specs ["battery" ]
23+ self .storage = specs ["storage" ]
24+
25+ except Exception as e :
26+ print ("All attributes not passed in specs" )
27+ exit ()
28+
29+ def getSpecifications (self ):
30+ print (f"Model: { self .model } " )
31+ print (f"CPU: { self .cpu } " )
32+ print (f"GPU: { self .gpu } " )
33+ print (f"RAM: { self .ram } " )
34+ print (f"Display: { self .display } " )
35+ print (f"Battery: { self .battery } " )
36+ print (f"Storage: { self .storage } " )
37+
38+
39+
40+
41+ """
42+ Single-level Inheritance
43+ (Child Class)
44+ """
45+ class GamingLaptop (Laptop ):
46+ def __init__ (self ,specs :dict ):
47+ print ("Gaming Laptop" )
48+ #Set the passed specs
49+ super ().setSpecifications (specs )
50+
51+ # Gaming laptoip features (extra)
52+ self .refresh_rate = "144 Hz"
53+ self .response_time = "2ms"
54+
55+ def getGamingSpecs (self ):
56+ super ().getSpecifications ()
57+ print (f"Refresh Rate: { self .refresh_rate } " )
58+ print (f"Response Time: { self .response_time } " )
59+
60+
61+
62+
63+
64+
65+ if __name__ == "__main__" :
66+
67+ gaming_specs = {
68+ "cpu" : "i7 12th Gen" ,
69+ "gpu" : "RTX 3070 Ti" ,
70+ "ram" : "16 GB" ,
71+ "display" : "1440p" ,
72+ "battery" : "90 WHr" ,
73+ "storage" : "1 TB NVME M.2 SSD"
74+ }
75+
76+ # "model": "ASUS TUF Gaming A15",
77+
78+ gl = GamingLaptop (specs = gaming_specs )
79+ gl .getGamingSpecs ()
0 commit comments