We'll be build a mini Uber simulation in Python using object-oriented programming (OOP).
Our goal is to model how Uber works at a small scale β drivers, riders, and rides using classes and methods.
I have written tests to guide you through the project. Please do not put your files inside the tests folder.
By the end of this project, you should be able to:
- Create and use classes and objects in Python.
- Define attributes and methods cleanly.
- Model relationships between objects (composition).
- Write and pass unit tests that validate program behavior.
| Class | Purpose |
|---|---|
Driver |
Represents a driver with a name, car model, and ride history. |
Rider |
Represents a user who can request rides and rate drivers. |
Ride |
Represents a single trip connecting a driver and rider. |
Uber |
Manages drivers, riders, and rides (like a dispatcher). |
- Implement
DriverandRiderclasses. - Each should have a few attributes (e.g. name, car model, ride history).
- Implement
__str__()or__repr__()for readable output. - β Tests will check creation and default values.
- Implement a
Rideclass with attributes:driverriderdistance(float, km)cost(calculated viaRATE_PER_KM)status("requested","in_progress","completed")
- Implement methods:
start_ride()complete_ride()
- β Tests will check status transitions and cost correctness.
- Create an
Uberclass that:- Keeps a list of available drivers.
- Assigns drivers to rides.
- Manages active and completed rides.
- Prevent busy drivers from being reassigned.
- β Tests will check correct assignment and driver availability reset.
- Riders can rate drivers (1β5 stars) after a ride completes.
- Drivers keep a record of ratings and an average score.
- β Tests will verify correct average calculation.
All tests are written using unittest.
To run them:
python -m unittest tests/test_blah.py