-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOOP_Auto.py
108 lines (72 loc) · 2.24 KB
/
OOP_Auto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# import ... Modulimporte
# class Klassendefinitionen
class Auto():
autocounter=0 # statische Variable/ Klassenvariable
def printCounter(): # statische Funktion/ Klassenfunktion
if Auto.autocounter > 1:
print(f"Es sind {Auto.autocounter} Autos auf den Straßen.")
elif Auto.autocounter == 1:
print("Es ist nur ein Auto auf den Straßen.")
else: print("Es sind keine Autos mehr auf den Straßen.")
def __init__(self, spd, make="Auto", maxP=4):
self.marke=make
self.geschwindigkeit=spd
self.maxPassenger=maxP
Auto.autocounter+=1
def __del__(self):
del self
Auto.autocounter-=1
def __add__(self, _):
return self.maxPassenger + _.maxPassenger
def __gt__(self, _):
if self.maxPassenger > _.maxPassenger:
return True
else: return False
def __repr__(self):
return f"Auto {self.marke}, {self.maxPassenger}"
def __str__(self):
return f"Auto vom Typ {self.marke}"
def tolleFunktion(self):
print("Ich bin eine tolle Methode.")
def fahren(self):
print("Auto fährt.")
class PKW(Auto):
pass
class LKW(Auto):
def __init__(self,spd, make="LKW", maxP=1):
super().__init__(self, spd)
self.maxLoad=1000
def fahren(self, p=True):
if p:
print("LKW macht BrummBrumm.")
else:
Auto.fahren(self)
# def Funktionsdefinitionen
def tolleFunktion():
print("Ich bin eine tolle Funktion.")
if __name__ == "__main__":
bmw=Auto(100)
bmw.marke="BMW"
print(bmw.marke)
trabant=Auto(0, maxP=3)
print(trabant.marke)
trabant.marke="Trabant"
print(trabant.marke)
print(bmw.marke)
trabant.marke="trabbi"
print(trabant.marke)
bmw.autocounter=3
print(Auto.autocounter)
print(Auto.autocounter)
print(bmw)
print(bmw>trabant)
trabant
Auto.printCounter()
tolleFunktion()
bmw={"marke":"BMW", "Geschwindigkeit":100}
brummi = LKW("Brummi",100)
brummi.maxLoad = 2000
print(brummi.maxLoad, Auto.autocounter)
brummi.fahren(p=False)
print(LKW.mro()) # Method Resolution Order
print(type(brummi))