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

Classes and Object-Oriented Python Python practice problems

Objects, attributes, methods, constructors, composition, and basic inheritance.

18 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

  • class · methods
  • encapsulation · state
  • class · reuse
  • aggregation · class
  • inheritance · override
PRACTICE OUTCOME

What this topic builds

Learn the idea once, use it across the exercises, and explain why your approach works.

ORDERED PRACTICE

All 18 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #153
    Model a rectangle class: Room object

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

    StarterPremium
  2. #154
    Model a rectangle class: Decimal rectangle

    Use the same class with decimal dimensions.

    StarterPremium
  3. #155
    Model a bank account: Normal transactions

    Apply deposits and withdrawals to one account object.

    StarterPremium
  4. #156
    Model a bank account: Reject overdraft

    Ignore a withdrawal larger than the available balance.

    StarterPremium
  5. #157
    Model a student grade: Passing student

    Create a student and determine the result from the average.

    BeginnerPremium
  6. #158
    Model a student grade: Failing boundary

    Classify an average below the pass mark.

    BeginnerPremium
  7. #159
    Build a shopping cart: Two-item cart

    Add two product lines and calculate the cart total.

    BeginnerPremium
  8. #160
    Build a shopping cart: Empty cart

    An empty cart has a total of zero.

    BeginnerPremium
  9. #161
    Use inheritance for employees: Manager bonus

    Calculate a manager's pay using a fixed bonus.

    BeginnerPremium
  10. #162
    Use inheritance for employees: Developer overtime

    Calculate a developer's pay using overtime hours.

    BeginnerPremium
  11. #163
    Protect temperature with a property: Valid temperature

    Store a normal temperature through the validated property.

    BeginnerPremium
  12. #164
    Protect temperature with a property: Impossible temperature

    Reject a value below absolute zero.

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

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

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

    Distinguish two editions with different ISBN values.

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

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

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

    A valid item with no units has zero inventory value.

    IntermediatePremium
  17. #169
    Model composition: Petrol car

    Start a car composed with a petrol engine.

    IntermediatePremium
  18. #170
    Model composition: Electric car

    Reuse the same relationship with an electric engine description.

    AdvancedPremium