Welcome to my Python Object-Oriented Programming assignments repository! This project showcases my understanding of core OOP concepts through practical implementations.
Repository: Python-OOP-Projects-PLP
Author: Paul Mbui
Course: PLP - Python Programming
Topic: Object-Oriented Programming (OOP)
This repository contains two comprehensive assignments that demonstrate mastery of OOP principles:
- Assignment 1: Superhero Management System
- Assignment 2: Transportation System (Polymorphism Challenge)
- Python 3.6 or higher installed on your system
- Basic understanding of Python syntax
- A code editor (VS Code, PyCharm, or any text editor)
- Clone the repository
git clone https://github.com/paulmbui20/Python-OOP-Projects-PLP.git
cd Python-OOP-Projects-PLP
- Verify Python installation
python --version
- Run the assignments
# Run Assignment 1
python assignment1.py
# Run Assignment 2
python assignment2.py
A comprehensive class-based system for managing superheroes with different abilities and characteristics.
- β
Custom class creation (
Superhero
) - β Constructor implementation with instance variables
- β Multiple attributes (name, power, energy, health)
- β Various methods (use_power, rest, show_stats, take_damage)
- β
Inheritance:
FlyingHero
andSpeedsterHero
classes - β
Encapsulation: Private health attribute (
__health
) - β
Polymorphism: Different implementations of
use_power()
method
Superhero (Base Class)
βββ FlyingHero (Can fly at altitude)
βββ SpeedsterHero (Super speed abilities)
use_power()
- Uses the hero's special abilityrest()
- Recovers energyshow_stats()
- Displays current statisticstake_damage()
- Handles damage with encapsulationget_health()
- Getter method for private health attribute
# Create a flying superhero
hero = FlyingHero("Sky Falcon", "Wind Blast", 90, 500)
hero.show_stats()
hero.fly()
hero.use_power()
hero.rest()
- Negative damage values
- Energy depletion (can't use powers when tired)
- Maximum energy cap (100)
- Health reaching zero (defeat scenario)
- Rest when already at full energy
A polymorphic demonstration featuring various modes of transportation, each with unique movement behaviors.
- β
Base
Vehicle
class with common interface - β Multiple vehicle types with inheritance
- β
Polymorphism: Same
move()
method, different behaviors - β Vehicle-specific methods and attributes
- β State management (moving/stopped)
- Car π - Drives on roads, can honk, needs fuel
- Plane
βοΈ - Flies through the sky, takes off and lands - Boat π€ - Sails on water, has anchor, carries passengers
- Bicycle π΄ - Pedals along, has gears, rings bell
- Train π - Runs on tracks, blows whistle
vehicles = [Car("Sports Car"), Plane("Jet"), Boat("Cruiser")]
# Same method name, different behaviors!
for vehicle in vehicles:
vehicle.move()
# Output:
# π Sports Car is driving on the road! Vroom vroom!
# βοΈ Jet is flying through the sky at 10000 feet!
# π€ Cruiser is sailing across the water! Splash splash!
Car:
honk()
- Makes horn soundrefuel()
- Adds fuel- Fuel management system
Plane:
takeoff()
- Launches into airland_plane()
- Returns to ground- Altitude tracking
Boat:
anchor()
- Drops anchor to stopboard_passengers()
- Adds passengers- Passenger counting
Bicycle:
change_gear()
- Shifts gearsring_bell()
- Rings bicycle bell- Gear validation
Train:
blow_whistle()
- Sounds train whistle- Multiple cars attribute
- Empty vehicle names (defaults to "Unknown Vehicle")
- Negative passenger counts
- Invalid gear numbers
- Out of fuel scenarios
- Already stopped/already moving states
Creating blueprints (classes) and instances (objects) with specific characteristics.
Initializing objects with unique values using the constructor method.
Each object maintains its own state with unique attribute values.
Functions that define object behaviors and actions.
Child classes inherit attributes and methods from parent classes:
FlyingHero
andSpeedsterHero
inherit fromSuperhero
- All vehicle types inherit from
Vehicle
Same method name produces different behaviors:
use_power()
works differently for each hero typemove()
is unique for each vehicle type
Private attributes protect internal data:
__health
in Superhero class- Accessed only through getter methods
- Input validation for edge cases
- Checking for negative values
- Range validation (gears, fuel, energy)
- Empty string handling
- Clear class hierarchies
- Logical method grouping
- Descriptive variable names
- Comprehensive comments
- Main function demonstrations
- Multiple test scenarios
- Edge case verification
- Polymorphism showcases
Through these assignments, I've gained practical experience with:
β
Class Design: Structuring classes with appropriate attributes and methods
β
Inheritance Planning: Creating logical parent-child relationships
β
Polymorphism Implementation: Using method overriding effectively
β
Encapsulation Practice: Protecting data with private attributes
β
Code Reusability: Reducing repetition through inheritance
β
Real-world Modeling: Translating real objects into code structures
β
Edge Case Handling: Making robust, error-resistant programs
Problem: Initially confused about when to use __
prefix
Solution: Learned that private attributes protect sensitive data from external modification
Problem: Wasn't sure if child class methods completely replace parent methods
Solution: Discovered that child methods override parent methods, but super()
can call parent version
Problem: Making sure all subclasses implement required methods correctly
Solution: Tested each class individually, then together in a list to verify polymorphic behavior
Problem: Programs crashed with unexpected inputs
Solution: Added validation checks before processing values (negative numbers, empty strings, etc.)
- OOP makes code more organized - Related data and functions stay together in classes
- Inheritance reduces repetition - Common features go in parent class
- Polymorphism adds flexibility - Same interface, different implementations
- Encapsulation protects data - Private attributes prevent unwanted changes
- Planning is important - Think about class structure before coding
- Language: Python 3.x
- Paradigm: Object-Oriented Programming
- Concepts: Classes, Objects, Inheritance, Polymorphism, Encapsulation
Python-OOP-Projects-PLP/
β
βββ assignment1.py # Superhero Management System
βββ assignment2.py # Transportation System
βββ README.md # Project documentation (this file)
The program will:
- Create three different types of heroes
- Demonstrate each hero's unique abilities
- Show energy management and health system
- Display polymorphism with different power usage
- Test edge cases like exhaustion and damage
The program will:
- Create five different vehicle types
- Demonstrate polymorphic
move()
method - Show unique features for each vehicle
- Test vehicle-specific methods
- Validate edge cases and error handling
Potential enhancements for these projects:
- Add a battle system for superheroes
- Implement hero team formations
- Create a vehicle race simulation
- Add fuel consumption rates for vehicles
- Include weather effects on vehicle movement
- Build a GUI interface using tkinter
- Save hero/vehicle data to files
- Add more vehicle types (Helicopter, Submarine, etc.)
This is a learning project, but suggestions and feedback are welcome! If you spot any issues or have ideas for improvement:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Paul Mbui
GitHub: @paulmbui20
Feel free to reach out if you have questions about the code or want to discuss OOP concepts!
This project is created for educational purposes as part of the PLP Python Programming course.
- PLP Academy for the comprehensive Python OOP curriculum
- Course instructors for clear explanations and examples
- Fellow students for collaborative learning
Want to learn more about OOP in Python? Check out:
Last Updated: October 4, 2025