This module focuses on object-oriented programming in Python, covering attributes, methods, operator overloading, and class-level versus instance-level attributes.
- Solution
- Description:
Task "Developer - Not Just a Coder":
- Implement a
House
class with attributes for the name and number of floors. The class should include a methodgo_to
that prints the floor numbers from 1 to the specified floor or an error message if the floor doesn't exist.
- Implement a
- Solution
- Description:
Task "Magical Buildings":
- Extend the
House
class to include special methods like__len__
, which returns the number of floors, and__str__
, which provides a formatted string representation of the house.
- Extend the
- Solution
- Description:
Task "Operator Overloading":
- Implement comparison operators (
__eq__
,__lt__
,__le__
, etc.) for theHouse
class to compare buildings by their number of floors. Also, implement the__add__
,__radd__
, and__iadd__
methods to increase the number of floors.
- Implement comparison operators (
- Solution
- Description:
Task "Construction History":
- Add a class-level attribute
houses_history
to track all created house objects. Implement the__new__
and__del__
methods to automatically record new houses and log when a house is demolished.
- Add a class-level attribute
- Solution
- Description:
Task "UrTube Platform":
- Implement a set of classes (
User
,Video
,UrTube
) to simulate the behavior of a video-sharing platform, including user registration, video uploading, and video watching with age restrictions and playback tracking.
- Implement a set of classes (