Classes and Object-Oriented Python Python practice problems
Objects, attributes, methods, constructors, composition, and basic inheritance.
Core concepts
Problem-solving patterns
- class · methods
- encapsulation · state
- class · reuse
- aggregation · class
- inheritance · override
What this topic builds
Learn the idea once, use it across the exercises, and explain why your approach works.
All 18 problems in this topic
Work from top to bottom to build the concept gradually.
- #153Model a rectangle class: Room objectStarterPremium
Create a Rectangle for a room and call its measurement methods.
- #154Model a rectangle class: Decimal rectangleStarterPremium
Use the same class with decimal dimensions.
- #155Model a bank account: Normal transactionsStarterPremium
Apply deposits and withdrawals to one account object.
- #156Model a bank account: Reject overdraftStarterPremium
Ignore a withdrawal larger than the available balance.
- #157Model a student grade: Passing studentBeginnerPremium
Create a student and determine the result from the average.
- #158Model a student grade: Failing boundaryBeginnerPremium
Classify an average below the pass mark.
- #159Build a shopping cart: Two-item cartBeginnerPremium
Add two product lines and calculate the cart total.
- #160Build a shopping cart: Empty cartBeginnerPremium
An empty cart has a total of zero.
- #161Use inheritance for employees: Manager bonusBeginnerPremium
Calculate a manager's pay using a fixed bonus.
- #162Use inheritance for employees: Developer overtimeBeginnerPremium
Calculate a developer's pay using overtime hours.
- #163Protect temperature with a property: Valid temperatureBeginnerPremium
Store a normal temperature through the validated property.
- #164Protect temperature with a property: Impossible temperatureIntermediatePremium
Reject a value below absolute zero.
- #165Customize book display and equality: Same ISBNIntermediatePremium
Treat books with matching ISBNs as the same edition even if a title varies.
- #166Customize book display and equality: Different ISBNIntermediatePremium
Distinguish two editions with different ISBN values.
- #167Use a dataclass for inventory: Stock itemIntermediatePremium
Create a concise inventory object and calculate its total stock value.
- #168Use a dataclass for inventory: Zero quantityIntermediatePremium
A valid item with no units has zero inventory value.
- #169Model composition: Petrol carIntermediatePremium
Start a car composed with a petrol engine.
- #170Model composition: Electric carAdvancedPremium
Reuse the same relationship with an electric engine description.