Answer to Question #270407 in Python for Peaches

Question #270407

Create a class representing a student. Include characteristics as student, number, first and last name, overall GPA, 

classification, and major. Write at least 1 default constructor. Include properties for each of the data items. 

Create a second class that instantiates the first class with information about yourself. In the second class, create a 

method that displays your name and GPA. 


1
Expert's answer
2021-11-24T13:49:02-0500
class Student:
    def __init__(self, student="Default student", number=0, first_name="Default first name",
                 last_name="Default last name", gpa=0, classification="Default classification", major="Default major",
                 **kwargs):
        self._student = student
        self._number = number
        self._first_name = first_name
        self._last_name = last_name
        self._gpa = gpa
        self._classification = classification
        self._major = major

    @property
    def student(self):
        return self._student

    @property
    def number(self):
        return self._number

    @property
    def first_name(self):
        return self._first_name

    @property
    def last_name(self):
        return self._last_name

    @property
    def gpa(self):
        return self._gpa

    @property
    def classification(self):
        return self._classification

    @property
    def major(self):
        return self._major


class MyStudent(Student):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def display_name_and_gpa(self):
        return f"{self.first_name} {self.last_name} {self.gpa}"


john_doe = MyStudent(first_name="John", last_name="Doe", gpa=3.14)
print(john_doe.display_name_and_gpa())

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS