scientific-programming-exer.../ex_17.py

60 lines
2.0 KiB
Python

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):
Student.__init__(self, name, age, birthplace, semester, studium)
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()