Basic Exercise with Solution on Class Object Method


  1. Basic Exercise on Object Oriented Programming
  2. Create one class student_kit
  3. Within the student_kit class create one class attribute principal name ( Mr ABC )
  4. Create one attendance method and take input as number of days.
  5. While creating student take input their name .
  6. Create one certificate for each student by taking input of number of days present in class.

Exercise Solution
class student_kit():
    principal_name='Mr ABC'
    
    def __init__(self,name):
        self.name=name
    def attendance(self,days):         
        self.present=days+10
        print("Name : ",self.name)
        print("Present :",self.present)
        print("Principal : ",self.principal_name)
kalu=student_kit("Kalu")         
kalu.attendance(20)
Output
Name :  Kalu
Present : 30

Answer these Questions

  1. What is the name of the method used in student_kit class ?
  2. What is the class attribute used in above code ?
  3. Which is the object created in above code ?
  4. How the method got access to class attributes ?
  5. What is the instance attribute in above code ?
  6. What is the data type of the created object ( kalu) ?

Answers

  1. attendance
  2. principal_name
  3. kalu
  4. self.principal_name
  5. self.present
  6. print(type(kalu)) # <class '__main__.student_kit'>
How the object can access the instance attribute ?
print(kalu.present) # 30
Tutorial on Class Object & Method Exercise constructor ( basic )
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



15-05-2023

We greatly appreciate your contribution in sharing your invaluable response.




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