Teil 6 "Objekte ist neu
Repository aufgeräumt.
This commit is contained in:
BIN
teil6/__pycache__/person.cpython-39.pyc
Normal file
BIN
teil6/__pycache__/person.cpython-39.pyc
Normal file
Binary file not shown.
9
teil6/anschrift.py
Normal file
9
teil6/anschrift.py
Normal file
@@ -0,0 +1,9 @@
|
||||
class Anschrift:
|
||||
def __init__(self, strasse, hausnummer, plz, ort):
|
||||
self.strasse = strasse
|
||||
self.hausnummer = hausnummer
|
||||
self.plz = plz
|
||||
self.ort = ort
|
||||
|
||||
def __str__(self):
|
||||
return self.strasse + ' ' + self.hausnummer + '\n' + self.plz + ' ' + self.ort
|
5
teil6/person.py
Normal file
5
teil6/person.py
Normal file
@@ -0,0 +1,5 @@
|
||||
class Person:
|
||||
# Konstruktor
|
||||
def __init__(self,vorname, name):
|
||||
self.vorname = vorname
|
||||
self.name = name
|
16
teil6/personMitAnschrift.py
Normal file
16
teil6/personMitAnschrift.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from anschrift import Anschrift
|
||||
|
||||
class Person:
|
||||
# Konstruktor
|
||||
def __init__(self,vorname, name,strasse,hausnummer, plz,ort):
|
||||
self.vorname = vorname
|
||||
self.name = name
|
||||
self.anschrift = Anschrift(strasse,hausnummer,plz,ort)
|
||||
|
||||
|
||||
def format(self):
|
||||
|
||||
return self.vorname + ' ' + self.name
|
||||
def __str__(self):
|
||||
return self.format() + '\n' + str(self.anschrift)
|
||||
|
4
teil6/useperson.py
Normal file
4
teil6/useperson.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from person import Person
|
||||
|
||||
p = Person('Olli','Graf')
|
||||
print(p.vorname)
|
34
teil6/vererbung.py
Normal file
34
teil6/vererbung.py
Normal file
@@ -0,0 +1,34 @@
|
||||
class Fahrzeug:
|
||||
def __init__(self, marke, modell, farbe):
|
||||
self.marke = marke
|
||||
self.modell = modell
|
||||
self.farbe = farbe
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.marke} {self.modell} {self.farbe})'
|
||||
|
||||
#Klasse Auto erbt von Fahrzeug
|
||||
class Auto(Fahrzeug):
|
||||
def __init__(self, marke, modell, farbe, ps):
|
||||
super().__init__(marke, modell, farbe)
|
||||
self.ps = ps
|
||||
|
||||
def __str__(self):
|
||||
return f'{super().__str__()} mit {self.ps} PS'
|
||||
|
||||
#Klasse Fahhrad erbt von Fahrzeug
|
||||
class Fahrrad(Fahrzeug):
|
||||
def __init__(self, marke, modell, farbe):
|
||||
super().__init__(marke, modell, farbe)
|
||||
|
||||
def __str__(self):
|
||||
return super().__str__()
|
||||
|
||||
|
||||
bond = Auto('Aston Martin','DB5','grau','286')
|
||||
mcfly = Auto('Delorean', 'DMC-12','grau','132')
|
||||
eliot = Fahrrad('Kuwahara','ET-1','weiß')
|
||||
|
||||
print(str(bond))
|
||||
print(str(mcfly))
|
||||
print(str(eliot))
|
Reference in New Issue
Block a user