How can create class Person :( - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: How can create class Person :( (/thread-22646.html) |
How can create class Person :( - Azilkhan - Nov-21-2019 Hey guys:) Who can help me ? Please guys help me ((((( Create a class Person which has attributes name, age. Create a class KazguuStudent which inherits from Person, has attribute course_level and method greet(). Create a class KazguuTeacher which also inherits from Person and has method greet(). Method greet() must print following attrubutes for KazguuStudent: "Hello! My name is [name]. I am [age] years old. I study in [course_level] course at Kazguu." Method greet() must print following attrubutes for KazguuTeacher: "Hello! My name is [name]. I am [age] years old. I teach [course_level] course at Kazguu." Create object student from class KazguuStudents and call method greet(). Create object teacher from class KazguuTeacher and call method greet(). Example: Hello! My name is Arman. I am 20 years old. I study in 2 course at Kazguu. Hello! My name is Valya. I am 30 years old. I teach 3 course at Kazguu. RE: How can create class Person :( - DeaD_EyE - Nov-21-2019 class Person: """ Create a class Person which has attributes name, age and name. """ def __init__(self, name, age, *args, **kwargs): self.name = name self.age = age super().__init__(*args, **kwargs) class KazguuStudent(Person): """ Create a class KazguuStudent which inherits from Person. It has attribute course_level and method greet(). """ def __init__(self, course_level, *args, **kwargs): super().__init__(*args, **kwargs) self.course_level = course_level def greet(self): return self.name, self.age, self.course_level student1 = KazguuStudent(name='A', age='F', course_level='Foo')The rest is you own task. The super() calls the ancestors. The *args and **kwargs are used to supply the __init__ method of the ancestor with the right arguments.
|