pyPython Practice LabFrom first print to final round
TOPIC 10 OF 18

Object-Oriented Python Python practice problems

Model state and behavior with classes, inheritance, composition, properties, and data classes.

20 exercises8+ conceptsBeginner → interview context
Start this topic
WHAT YOU WILL PRACTISE

Core concepts

Model a rectangle classModel a bank accountModel a student gradeBuild a shopping cartUse inheritance for employeesProtect temperature with a propertyCustomize book display and equalityUse a dataclass for inventory
REUSABLE THINKING

Problem-solving patterns

  • Model state in objects and expose behavior through focused methods
INTERVIEW SIGNALS

Reported company tags

AmazonMicrosoftIBMMeta
Community-reported tags are guidance, not guarantees.
ORDERED PRACTICE

All 20 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #181
    Model a rectangle class: Room object

    Create a Rectangle for a room and call its measurement methods.

    IntermediatePremium
  2. #182
    Model a rectangle class: Decimal rectangle

    Use the same class with decimal dimensions.

    IntermediatePremium
  3. #183
    Model a bank account: Normal transactions

    Apply deposits and withdrawals to one account object.

    IntermediatePremium
  4. #184
    Model a bank account: Reject overdraft

    Ignore a withdrawal larger than the available balance.

    IntermediatePremium
  5. #185
    Model a student grade: Passing student

    Create a student and determine the result from the average.

    IntermediatePremium
  6. #186
    Model a student grade: Failing boundary

    Classify an average below the pass mark.

    IntermediatePremium
  7. #187
    Build a shopping cart: Two-item cart

    Add two product lines and calculate the cart total.

    IntermediatePremium
  8. #188
    Build a shopping cart: Empty cart

    An empty cart has a total of zero.

    IntermediatePremium
  9. #189
    Use inheritance for employees: Manager bonus

    Calculate a manager's pay using a fixed bonus.

    IntermediatePremium
  10. #190
    Use inheritance for employees: Developer overtime

    Calculate a developer's pay using overtime hours.

    IntermediatePremium
  11. #191
    Protect temperature with a property: Valid temperature

    Store a normal temperature through the validated property.

    IntermediatePremium
  12. #192
    Protect temperature with a property: Impossible temperature

    Reject a value below absolute zero.

    IntermediatePremium
  13. #193
    Customize book display and equality: Same ISBN

    Treat books with matching ISBNs as the same edition even if a title varies.

    IntermediatePremium
  14. #194
    Customize book display and equality: Different ISBN

    Distinguish two editions with different ISBN values.

    IntermediatePremium
  15. #195
    Use a dataclass for inventory: Stock item

    Create a concise inventory object and calculate its total stock value.

    IntermediatePremium
  16. #196
    Use a dataclass for inventory: Zero quantity

    A valid item with no units has zero inventory value.

    IntermediatePremium
  17. #197
    Model composition: Petrol car

    Start a car composed with a petrol engine.

    IntermediatePremium
  18. #198
    Model composition: Electric car

    Reuse the same relationship with an electric engine description.

    IntermediatePremium
  19. #199
    Create a countdown iterator: Custom countdown

    Iterate from three to zero using the iterator protocol.

    IntermediatePremium
  20. #200
    Create a countdown iterator: Iterator edge

    A countdown starting at zero still yields one element.

    IntermediatePremium