This repository contains beginner-friendly practice exercises covering the core building blocks of Object-Oriented Programming (OOP) in Python: classes, constructors (__init__), self, and instance attributes.
why.py— Contains five independent practice programs, each demonstrating a different OOP concept.
Demonstrates how to define a class, initialize objects using a constructor, and create multiple independent instances.
Simulates a simple banking system with deposit and withdraw methods, including a conditional check to prevent overdrawing the balance.
Shows how to create several objects of the same class, store them in a list, and iterate over them using a for loop.
Demonstrates how instance attributes can be updated over time using methods like increment() and reset().
Covers methods that return calculated values (area() and perimeter()) based on instance attributes.
Make sure you have Python 3 installed, then run:
python why.pybmw
X5
2022
porshe
X3
2021
------------------------------
500
Insufficient balance
500
------------------------------
aby hayat by umera ahmad has 3000 pages.
naval by nimra has 7000 pages.
bakt by mehru has 3000 pages.
------------------------------
5
0
------------------------------
8
12
18
18
By working through this file, you will understand:
- How to define a class and create objects (instances) from it
- The role of the
__init__constructor in initializing object state - How
selfrefers to the specific instance a method is called on - The difference between instance attributes and shared state
- How to use conditionals inside methods to control object behavior
- How to store multiple objects in a list and process them with a loop
- How to write methods that return computed values