Object-Oriented Python Python practice problems
Model state and behavior with classes, inheritance, composition, properties, and data classes.
Core concepts
Problem-solving patterns
- Model state in objects and expose behavior through focused methods
Reported company tags
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #181Model a rectangle class: Room objectIntermediatePremium
Create a Rectangle for a room and call its measurement methods.
- #182Model a rectangle class: Decimal rectangleIntermediatePremium
Use the same class with decimal dimensions.
- #183Model a bank account: Normal transactionsIntermediatePremium
Apply deposits and withdrawals to one account object.
- #184Model a bank account: Reject overdraftIntermediatePremium
Ignore a withdrawal larger than the available balance.
- #185Model a student grade: Passing studentIntermediatePremium
Create a student and determine the result from the average.
- #186Model a student grade: Failing boundaryIntermediatePremium
Classify an average below the pass mark.
- #187Build a shopping cart: Two-item cartIntermediatePremium
Add two product lines and calculate the cart total.
- #188Build a shopping cart: Empty cartIntermediatePremium
An empty cart has a total of zero.
- #189Use inheritance for employees: Manager bonusIntermediatePremium
Calculate a manager's pay using a fixed bonus.
- #190Use inheritance for employees: Developer overtimeIntermediatePremium
Calculate a developer's pay using overtime hours.
- #191Protect temperature with a property: Valid temperatureIntermediatePremium
Store a normal temperature through the validated property.
- #192Protect temperature with a property: Impossible temperatureIntermediatePremium
Reject a value below absolute zero.
- #193Customize book display and equality: Same ISBNIntermediatePremium
Treat books with matching ISBNs as the same edition even if a title varies.
- #194Customize book display and equality: Different ISBNIntermediatePremium
Distinguish two editions with different ISBN values.
- #195Use a dataclass for inventory: Stock itemIntermediatePremium
Create a concise inventory object and calculate its total stock value.
- #196Use a dataclass for inventory: Zero quantityIntermediatePremium
A valid item with no units has zero inventory value.
- #197Model composition: Petrol carIntermediatePremium
Start a car composed with a petrol engine.
- #198Model composition: Electric carIntermediatePremium
Reuse the same relationship with an electric engine description.
- #199Create a countdown iterator: Custom countdownIntermediatePremium
Iterate from three to zero using the iterator protocol.
- #200Create a countdown iterator: Iterator edgeIntermediatePremium
A countdown starting at zero still yields one element.