Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ def fuel_up(self):
return "Full tank"

def brake(self):
print("Braking the car.")
print("Braking the vehicle.")


class Bus(Vehicle):
def __init__(self, brand, model, year, seating_capacity):
super().__init__(brand, model, year)
self.seating_capacity = seating_capacity

def display_info(self):
"""Override display_info to include seating capacity."""
return f"{super().display_info()} with seating capacity of {self.seating_capacity} passengers"

def capacity_info(self):
"""Specific method for buses."""
return f"The bus can seat up to {self.seating_capacity} passengers."
21 changes: 15 additions & 6 deletions usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from Car import Car\n",
"from Motorcycle import Motorcycle\n",
"from Truck import Truck"
"from Truck import Truck\n",
"from Vehicle import Bus"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -23,24 +24,32 @@
"Car: Toyota Camry, 4 doors (2022)\n",
"Motorcycle: Harley-Davidson Iron 883, without sidecar (2021)\n",
"Truck: Volvo FH16, Max load: 25 tons (2020)\n",
"Mercedes Citaro (2023) with seating capacity of 50 passengers\n",
"The bus can seat up to 50 passengers.\n",
"Honk honk!\n",
"Meep meep!\n",
"HOOOOONK!\n"
"HOOOOONK!\n",
"Beep beep!\n"
]
}
],
"source": [
"car = Car(\"Toyota\", \"Camry\", 2022, 4)\n",
"motorcycle = Motorcycle(\"Harley-Davidson\", \"Iron 883\", 2021, False)\n",
"truck = Truck(\"Volvo\", \"FH16\", 2020, 25)\n",
"city_bus = Bus(\"Mercedes\", \"Citaro\", 2023, 50)\n",
"\n",
"print(car.display_info())\n",
"print(motorcycle.display_info())\n",
"print(truck.display_info())\n",
"print(city_bus.display_info())\n",
"print(city_bus.capacity_info()) \n",
"\n",
"\n",
"print(car.honk())\n",
"print(motorcycle.honk())\n",
"print(truck.honk())"
"print(truck.honk())\n",
"print(city_bus.honk()) "
]
}
],
Expand All @@ -60,7 +69,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
"version": "3.13.0"
}
},
"nbformat": 4,
Expand Down