0% found this document useful (0 votes)
27 views7 pages

Day1 of Oops Viva Prep

Uploaded by

queendiarys96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views7 pages

Day1 of Oops Viva Prep

Uploaded by

queendiarys96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Day 1 – Object Oriented Programming (OOP) Practice in Python

Topics for Day 1:

🔹 Basic Concepts

1. What is OOP (Object-Oriented Programming)


2. Class and Object
3. self Keyword
4. Defining Attributes and Methods
5. Instantiating Objects

🔹 Object Lifecycle

6. Constructors (__init__) and Destructors (__del__)


7. Default Constructors

🔹 Attributes in OOP

8. Class Attributes vs. Instance Attributes


9. Accessing and Modifying Attributes
10. The __dict__ Attribute

🔹 Methods in Classes

11. Instance Methods


12. Class Methods (@classmethod)
13. Static Methods (@staticmethod)

------------------------------------------------------------------------------------------------------------------------------

Easy Assignments

✅ 1. Class and Object


Assignment 1:
Create a class Car with attributes brand, model, and year. Create 2 objects of the class and print
their details.

Assignment 2:
Create a class Book with attributes title and author. Make two different book objects and
display their information.
✅ 2. Self Keyword
Assignment 1:
Create a class Student with attributes name and marks. Use self in constructor and method
display() to print details.

Assignment 2:
Create a class Product with attributes name, price. Add a method apply_discount(self,
percent) that uses self.price to apply discount.

✅ 3. Defining Attributes and Methods


Assignment 1:
Make a class Mobile with attributes brand, model, price and method show_details().

Assignment 2:
Make a class Employee with attributes name, salary. Add method give_bonus() that increases
salary by 10%.

✅ 4. Instantiating Objects
Assignment 1:
Create a class Animal with attribute species. Create two different objects lion and tiger.

Assignment 2:
Create a class Laptop with attributes brand, ram. Create 3 laptops using constructor and display
their specs.

✅ 5. Constructors and Destructors


Assignment 1:
Create a class File that prints "File Opened" in constructor and "File Closed" in destructor.

Assignment 2:
Create a class User with __init__() to initialize username and __del__() to print a goodbye
message.

✅ 6. Default Constructor
Assignment 1:
Create a class Shape with a default constructor that prints "Shape created".

Assignment 2:
Create a class Vehicle where default constructor assigns brand as "Unknown" and wheels as 4.

✅ 7. Class vs Instance Attributes


Assignment 1:
Create class Employee with class attribute company_name = "TechSoft" and instance attributes
name and salary.

Assignment 2:
Class Dog with instance attribute name and class attribute species = "Canine".

✅ 8. Accessing and Modifying Attributes


Assignment 1:
Create Movie class with title, year. Update the title using an object after creation.

Assignment 2:
Create Account class with balance. Create a method deposit() to increase balance.

✅ 9. The __dict__ Attribute


Assignment 1:
Create class Student with attributes name and marks. Print object attributes using __dict__.

Assignment 2:
Create class Car with attributes brand and price. Print full dictionary of the object.
✅ 10. Instance Methods
Assignment 1:
Class Person with method greet() that prints "Hello, I’m <name>".

Assignment 2:
Class Order with method calculate_total(self, tax_percent) that returns total price with
tax.

✅ 11. Class Methods (@classmethod)


Assignment 1:
Create a class Counter with class attribute count. Every time object is created, count increases.
Add show_count() class method.

Assignment 2:
Create a class School with class attribute school_name. Make class method
change_school(cls, new_name).

✅ 12. Static Methods (@staticmethod)


Assignment 1:
Create class MathTools with static method is_even(num).

Assignment 2:
Create class Validator with static method validate_email(email) that checks if '@' exists.

Hard Assignments

✅ 1. Class & Object


Assignment:
Create a class Library with a list of books. Allow users to borrow and return books. Track
which user has borrowed which book using a dictionary. Ensure books can't be borrowed twice.
✅ 2. Self Keyword
Assignment:
Create a class ShoppingCart where users can add multiple products using self. Each time a
product is added, store it in a self.cart list. Display full cart items using a method.

✅ 3. Defining Attributes and Methods


Assignment:
Create a class Recipe with attributes like name, ingredients, cooking_time. Add methods:
is_quick_recipe() (returns True if time < 30 mins) and add_ingredient().

✅ 4. Instantiating Objects
Assignment:
Make a class Task that takes a title and due date. Create a TaskManager class that keeps track of
all tasks created using object instantiation. Include method to show overdue tasks.

✅ 5. Constructors and Destructors


Assignment:
Create a class DatabaseConnection that connects in constructor and closes in destructor.
Simulate using print statements and test with multiple connections.

✅ 6. Default Constructor
Assignment:
Create a class Game that shows default values for level, score, and lives. Allow optional
values through overloaded constructor logic using default arguments.
✅ 7. Class vs Instance Attributes
Assignment:
Create a class Student. Track total number of students using a class attribute. Each student
should have name, grades (list). Add a method to update individual grades.

✅ 8. Accessing and Modifying Attributes


Assignment:
Create class Budget with categories like food, travel, bills. Modify values via a method
update_category(category, amount) and display budget summary.

✅ 9. dict Attribute
Assignment:
Create a class Project with attributes like title, deadline, team. Use __dict__ to export
project data as a dictionary for saving into a file (simulate this).

✅ 10. Instance Methods


Assignment:
Create class Ticket with attributes event_name, price, and quantity. Add method
buy_ticket(quantity) that updates available tickets and returns total cost.

✅ 11. Class Method


Assignment:
Create class Employee with class attribute employee_count. Use class method to show how
many employees are in each department (store count using dictionary by department).

✅ 12. Static Method


Assignment:
Create class TimeUtils with static method is_working_hour(hour) that returns True if hour is
between 9 and 17. Test for different hours without creating an object.

Good luck, and give your best!

You Can do it …
Prepared by Areeba Zafar

You might also like