Python Forum
How can create class Person :(
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can create class Person :(
#1
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.
Reply
#2
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Making a Class Person ? Kessie1971 3 1,140 Apr-23-2023, 05:20 PM
Last Post: deanhystad
  print(f"{person}:") SyntaxError: invalid syntax when running it AryaIC 11 16,374 Nov-07-2020, 10:17 AM
Last Post: snippsat
  Please help with Create Custom class Robot(): TheRealOne 5 3,189 Nov-05-2018, 03:41 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020