Skip to content
Open
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
48 changes: 34 additions & 14 deletions lab-oop_in_python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 0\n"
]
}
],
"source": [
"# Your code here\n",
"class Vehicle:\n",
" # Hint: Define __init__ method with parameters for max_speed and mileage\n",
" max_speed = 0\n",
" mileage = 0\n",
"\n",
" def __init__(self, max_speed= 0 , mileage=0):\n",
" self.max_speed = max_speed\n",
" self.mileage = mileage\n",
" pass\n",
"\n",
"# Example instantiation\n",
Expand All @@ -56,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -87,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -118,14 +131,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Base fare\n"
"Base fare with extra charge\n"
]
}
],
Expand All @@ -137,6 +150,9 @@
"\n",
"class Bus(Vehicle):\n",
" # Hint: Override fare method to include extra charges\n",
" def fare(self):\n",
" parent_fare = super().fare()\n",
" return parent_fare + \" with extra charge\"\n",
" pass\n",
"\n",
"school_bus = Bus()\n",
Expand All @@ -153,7 +169,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -188,14 +204,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Bus fare is: 5000\n"
"Total Bus fare is: 5500.0\n"
]
}
],
Expand All @@ -212,6 +228,10 @@
"\n",
"class Bus(Vehicle):\n",
" # Hint: Override fare method to include maintenance charge\n",
" def fare(self):\n",
" parent_fare = super().fare()\n",
" total_fare = parent_fare + parent_fare*10/100\n",
" return total_fare\n",
" pass\n",
"\n",
"school_bus = Bus(\"School Volvo\", 12, 50)\n",
Expand All @@ -228,7 +248,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 24,
"metadata": {},
"outputs": [
{
Expand All @@ -255,7 +275,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 25,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -287,7 +307,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -301,7 +321,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down