Exercise Solution on Object Oriented Programming


  1. Exercise on Object Oriented Programming
  2. Create one student_kit class. Student object should have name and section.

    Method : mark_sheet , input: mark in three subjects and output should print individual mark and sum of it
    Method : attendance sheet , input: Number of working days , Number of days attended. Percentage of attendance should be presented.
    Method : Final certificate : should display passed from College name and section.
  3. Update the above code to return Certificate showing total marks obtained and attendance in percentage by the student. ( Optional ) You can give grade A, B or C and decide Pass or Fail based on marks obtained ( as entered during generation of mark sheet )
  4. Use the above code to take three students details from user as input and print one by one each student details. ( Hint : Use dictionary having a list to store the data )
  5. Keep your student_kit class in a separate file ( student_kit.py ) . Create a new file using the above code for creating three student inputs. Call the class student_kit from your new file and use the methods to show marksheet , certificate , attendance etc for each student.Use this code in your new file to link the class.
     from student_kit  import student_kit

Exercise Solution
class student_kit():
    now=200  # Numbe of working days, class attribute 
    def __init__(self,name,section):
        self.name=name
        self.section=section
        
    def marksheet(self,mark1,mark2,mark3):
        self.mark1=mark1
        self.mark2=mark2
        self.mark3=mark3
        self.sum_marks=self.mark1 + self.mark2 + self.mark3
        return mark1+mark2+mark3
    
    def attendance(self,nop):         
        self.percentage_of_attendace=(nop/student_kit.now)*100
        print("Name of student is {}".format(self.name))
        print("No of days {} was absent is {}".format(self.name,student_kit.now-nop))
        print("percentage of attendance {}".format(self.percentage_of_attendace))
        

    def certificate(self):
        print("\n\n#### Certificate #####\n")
        print("Total marks obtained by",self.name, " is : ",self.sum_marks)
        print(" Attendance ",self.percentage_of_attendace,"%")  #access data from other methods
        
kalu=student_kit("Kalu","A")   #object kalu is created        
print("Student Name:",kalu.name," of Section :",kalu.section)
a=int(input("\n Enter maths marks: "))
b=int(input("Enter physics marks: "))
c=int(input("Enter Chemistry marks: "))

p=int(input("Enter no of days present: "))

kalu.attendance(p) 
print("Total Mark ",kalu.marksheet(a,b,c))
kalu.certificate()
    
Keep your student_kit class in a separate file ( student_kit.py ) . Create a new file using the above code for creating three student inputs. Call the class student_kit from your new file and use the methods to show mark sheet , certificate , attendance etc for each student.Use this code in your new file to link the class.

student.py
# Create the dictionary with three students
# For each student take marks in three subjects and attendance
# For each student display certificate using student_kit.

from student_kit import student_kit

my_dict={}

for i in range(0,3):
    n=input("Student Name : ")
    a=int(input("\n Enter maths marks: "))
    b=int(input("Enter physics marks: "))
    c=int(input("Enter Chemistry marks: "))

    p=int(input("Enter no of days present: "))


    my_dict.update({n:[a,b,c,p]})

print(my_dict)

for i in my_dict:
    obj=student_kit(i,"A")  #object  is created 
    obj.attendance(my_dict[i][3])
    print("Total Mark ",obj.marksheet(my_dict[i][0],my_dict[i][1],my_dict[i][2]))
    obj.certificate()
student_kit.py
class student_kit():
    now=200 # Number of working days, class attribute 
    def __init__(self,name,section):
        self.name=name
        self.section=section
        
    def marksheet(self,mark1,mark2,mark3):
        self.mark1=mark1
        self.mark2=mark2
        self.mark3=mark3
        self.sum_marks=self.mark1 + self.mark2 + self.mark3
        return mark1+mark2+mark3
    
    def attendance(self,nop):         
        self.percentage_of_attendace=(nop/student_kit.now)*100
        print("Name of student is {}".format(self.name))
        print("No of days {} was absent is {}".format(self.name,student_kit.now-nop))
        print("percentage of attendance {}".format(self.percentage_of_attendace))
        

    def certificate(self):
        print("\n\n#### Certificate #####\n")
        print("Total marks obtaind by",self.name, " is : ",self.sum_marks)
        print(" Attendace ",self.percentage_of_attendace,"%") #access data from other methods    
Tutorial on Class Object & Method
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer