Python program to read and print students information using two classes using simple inheritance. ((MSBTE Pratical Question))

Code:


class student:

    rollno = 0

    stud_name = ""

    stud_dept = ""

    def getdata(self):

     self.rollno = input("Enter your roll no: ")

     self.stud_name = input("Enter your name: ")

        self.stud_dept = input("Enter your department: ")

    def putdata(self):

        print("Student name:",self.stud_name)

        print("Roll no:",self.rollno)

        print("Department name:",self.stud_dept)

class marks(student):

    m1 = 0

    m2 = 0

    m3 = 0

    def get(self):

        self.m1 = int(input("Enter marks for m1: "))

        self.m2 = int(input("Enter marks for m2: "))

        self.m3 = int(input("Enter marks for m3: "))

    def put(self):

        print("m1:",self.m1)

        print("m2:",self.m2)

        print("m3:",self.m3)

        print("Total marks:",self.m1 + self.m2 + self.m3,"/300")

        print("Percentage:",((self.m1 + self.m2 + self.m3)/300)*100)

m1 = marks()

m1.getdata()

m1.get()

m1.putdata()

m1.put()


Output:

Comments

Popular posts from this blog

State use of pep and pip