2018-11-21 15:30:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Person(object):
|
|
|
|
def __init__(self, name, age, birthplace):
|
|
|
|
self.name = name
|
|
|
|
self.age = age
|
|
|
|
self.birthplace = birthplace
|
|
|
|
|
|
|
|
def about_myself(self):
|
|
|
|
print("I am {name}, {age} years old and was born in {birthplace}".format(**self.__dict__))
|
|
|
|
|
|
|
|
class Student(Person):
|
|
|
|
def __init__(self, name, age, birthplace, semester, studium):
|
|
|
|
Person.__init__(self, name, age, birthplace)
|
|
|
|
self.semester = semester
|
|
|
|
self.studium = studium
|
|
|
|
def about_myself(self):
|
|
|
|
Person.about_myself(self)
|
|
|
|
print("Also I am a student and I study {studium} in semester {semester}".format(**self.__dict__))
|
|
|
|
|
|
|
|
class Musician(Person):
|
|
|
|
def __init__(self, name, age, birthplace, instrument):
|
|
|
|
Person.__init__(self, name, age, birthplace)
|
|
|
|
self.instrument = instrument
|
|
|
|
def about_myself(self):
|
|
|
|
Person.about_myself(self)
|
|
|
|
print("Also I am a musician and I play {instrument}".format(**self.__dict__))
|
|
|
|
|
|
|
|
class FootballPlayer(Person):
|
|
|
|
def __init__(self, name, age, birthplace, football_team):
|
|
|
|
Person.__init__(self, name, age, birthplace)
|
|
|
|
self.football_team = football_team
|
|
|
|
def about_myself(self):
|
|
|
|
Person.about_myself(self)
|
|
|
|
print("Also I am a football player and I play in the {football_team}".format(**self.__dict__))
|
|
|
|
|
|
|
|
class StudenWhoHappensToPlayFootball(Student, FootballPlayer):
|
|
|
|
def __init__(self, name, age, birthplace, semester, studium, football_team):
|
2018-11-28 16:10:10 +00:00
|
|
|
Student.__init__(self, name, age, birthplace, semester, studium)
|
2018-11-21 15:30:46 +00:00
|
|
|
FootballPlayer.__init__(self, name, age, birthplace, football_team)
|
|
|
|
|
|
|
|
def about_myself(self):
|
|
|
|
Student.about_myself(self)
|
|
|
|
print("Also I am a football player and I play in the {football_team}".format(**self.__dict__))
|
|
|
|
|
|
|
|
|
|
|
|
if( __name__ == "__main__"):
|
|
|
|
p = Person("Emil", 12, "Dresden")
|
|
|
|
s = Student("Thomas", 22, "Duggendorf", 3, "Bachelor of Dye")
|
|
|
|
m = Musician("Gandalf", 3612, "Mittelerde", "Picolo")
|
|
|
|
f = FootballPlayer("Özil", 30, "Anatolien", "FC BAYERN")
|
|
|
|
sf = StudenWhoHappensToPlayFootball("Peter", 54, "Pentling", 10, "Philosopy", "FC Hinterdupfingen")
|
|
|
|
|
|
|
|
l = [p, s, m, f, sf]
|
|
|
|
for i in l:
|
|
|
|
i.about_myself()
|
|
|
|
|
|
|
|
|
|
|
|
|