File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ class Vehicle :
2+
3+ def __init__ (self , color , model ):
4+ self .color = color
5+ self .model = model
6+
7+ class Device :
8+
9+ def __init__ (self ):
10+ self .voltage = 12
11+
12+ class Car (Vehicle , Device ):
13+
14+ wheels = 0
15+
16+ def __init__ (self , color , model , year ):
17+ Vehicle .__init__ (self , color , model )
18+ Device .__init__ (self )
19+ self .year = year
20+
21+ def add_wheels (self , wheels ):
22+ self .wheels = wheels
23+
24+ @property
25+ def voltage (self ):
26+ return self ._voltage
27+
28+ @voltage .setter
29+ def voltage (self , volts ):
30+ print ("Warning: this can cause problems!" )
31+ self ._voltage = volts
32+
33+ @voltage .deleter
34+ def voltage (self ):
35+ print ("Warning: the radio will stop working!" )
36+ del self ._voltage
37+
38+ def __str__ (self ):
39+ return f'Car { self .color } : { self .model } : { self .year } '
40+
41+ def __eq__ (self , other ):
42+ return self .year == other .year
43+
44+ def __lt__ (self , other ):
45+ return self .year < other .year
46+
47+ def __add__ (self , other ):
48+ return Car (self .color + other .color ,
49+ self .model + other .model , int (self .year ) + int (other .year ))
You can’t perform that action at this time.
0 commit comments