Student Information

Student Information

Implement the concept of single inheritance using python. 

Create a base class named Person with instance member’s (name and age) and a constructor to initialize the data member’s

Create a derived class named Student with instance member’s (regno and percentage) and a constructor to initialize the data member’s , which inherits the Person class, and holds all the properties of the both Person class and  with the method named ‘display’ to display the details of instance member’s .
In the Main method get the student details, create the object for student, invoke the display() method in the Student class to displays all the details of the student.

Note: 
Strictly follow the naming conventions for variables and functions as specified in the problem description.
The student object should be student_obj

All the attribute values should be user inputs and store those values into the variables with the name: 

name for storing student name

age for storing student age

regno for storing student regno

percentage for storing student percetage

Sample Input 1: 

Enter the student name:

Ashok

Enter the student age:

21

Enter the student rollno:

715234

Enter the student percentage:

82.1

Sample Output 1:

Name:Ashok

Age:21

Rollno:715234

Percentage:82.1

Code :-

class Person:
    def __init__(self,name,age):
        self.name=name
        self.age=age
        
    def get_name(self):
        return self.name
    
    def get_age(self):
        return self.age
    
class Student(Person):
    def __init__(self,name,age,regno,percentage):
        self.regno=regno
        self.percentage=percentage
        Person.__init__(self,name,age)
    
    def get_regno(self):
        return self.regno
        
    def get_percentage(self):
        return self.percentage
        
    def display(self):
        print("Name:"+self.get_name()+"\nAge:"+str(self.get_age())+"\nRollno:"+str(self.get_regno())+"\nPercentage:"+str(self.get_percentage()))
        
        
name=input("Enter the student name:\n")
age=int(input("Enter the student age:\n"))
regno=int(input("Enter the student rollno:\n"))
percentage=float(input("Enter the student percentage:\n"))

student_obj=Student(name,age,regno,percentage)

student_obj.display()

Leave a Comment

Your email address will not be published. Required fields are marked *

x