Welcome to the Object-Oriented Programming Assignment for Week 5!
This activity challenges you to design your own class, use constructors, encapsulation, and add an inheritance layer for real-world modeling.
week-5-assignment/
├── superhero.py # Contains the Superhero class and logic
├── main.py # Entry point to create and interact with superhero objects
├── polymorphism-challenge/
│ ├── vehicles.py # Contains polymorphism challenge classes
│ ├── main.py # Polymorphism demo entry
│ └── README.md # Polymorphism challenge README
└── README.md # You're reading this!
We created a class called Superhero
that includes:
- Attributes:
name
,power
,health
, andcatchphrase
- Constructor: Initializes each superhero with unique values
- Methods:
introduce()
: Prints out the hero's name and catchphrasetake_damage(amount)
: Reduces healthheal(amount)
: Restores health
We also created a subclass (e.g. FlyingSuperhero
) that:
- Inherits from
Superhero
- Adds a method
fly()
to simulate flight - Overrides the
introduce()
method to add flight info
This demonstrates encapsulation and polymorphism in action.
cd week-5-assignment
python main.py
You'll be able to see superheroes created, damaged, healed, and performing actions like flying.
Meet Thunderbolt! “Justice never sleeps!"
Thunderbolt took 30 damage!
Thunderbolt healed 20 health!
Thunderbolt is flying through the sky! ✨
Hi, I'm Thunderbolt, the flying superhero! ✈️
Welcome to the Polymorphism Challenge for Week 5!
This challenge is designed to help you understand and practice polymorphism in Python using a real-world concept: vehicles with different modes of movement. 🚣️
Implement polymorphism by creating a base class called Vehicle
with a method move()
.
Then create multiple subclasses (e.g., Car
, Plane
, Boat
) that each override the move()
method with their own unique behavior.
This demonstrates how different objects can share the same method name but behave differently.
- Method:
move()
– A generic method for moving.
- Overrides
move()
– Prints"Driving on the road..."
- Overrides
move()
– Prints"Flying through the sky..."
- Overrides
move()
– Prints"Sailing across the water..."
cd week-5-assignment/polymorphism-challenge
python main.py
You’ll see different movement styles printed by each vehicle class, demonstrating polymorphism 535C in action.
Driving on the road... 🚗
Flying through the sky... ✈️
Sailing across the water... 🚤