From d27058b6585cf93d42d49777e0bf5f00bc8c3c59 Mon Sep 17 00:00:00 2001 From: marcismon20 Date: Wed, 1 Apr 2026 14:25:19 +0200 Subject: [PATCH] Add files via upload --- lab-oop_in_python.ipynb | 61 +++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/lab-oop_in_python.ipynb b/lab-oop_in_python.ipynb index 3142c5e..47996f6 100644 --- a/lab-oop_in_python.ipynb +++ b/lab-oop_in_python.ipynb @@ -30,17 +30,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100 100000\n" + ] + } + ], "source": [ "# Your code here\n", "class Vehicle:\n", " # Hint: Define __init__ method with parameters for max_speed and mileage\n", - " pass\n", + " def __init__(self, max_speed, mileage):\n", + " self.max_speed = max_speed\n", + " self.mileage = mileage\n", "\n", "# Example instantiation\n", - "modelX = Vehicle() # Create an instance of Vehicle\n", + "modelX = Vehicle(100, 100000) # Create an instance of Vehicle\n", "\n", "# Print attributes\n", "print(modelX.max_speed, modelX.mileage) # Expected output: (value of max_speed, value of mileage)" @@ -56,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -70,7 +80,9 @@ "source": [ "# Your code here\n", "class Vehicle:\n", - " pass\n", + " \n", + " def __init__(self):\n", + " pass\n", "\n", "# Example instantiation\n", "my_vehicle = Vehicle()\n", @@ -87,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -101,8 +113,9 @@ "source": [ "# Your code here\n", "class Bus(Vehicle):\n", - " pass\n", - "\n", + " def __init__(self):\n", + " super().__init__()\n", + " \n", "# Example instantiation\n", "school_bus = Bus()\n", "print(type(school_bus)) # Expected output: " @@ -118,14 +131,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Base fare\n" + "Base fare with extra charge\n" ] } ], @@ -136,9 +149,9 @@ " return \"Base fare\"\n", "\n", "class Bus(Vehicle):\n", - " # Hint: Override fare method to include extra charges\n", - " pass\n", - "\n", + " def fare(self):\n", + " return \"Base fare with extra charge\"\n", + " \n", "school_bus = Bus()\n", "print(school_bus.fare()) # Expected output: \"Base fare with extra charge\"" ] @@ -153,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -188,14 +201,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Total Bus fare is: 5000\n" + "Total Bus fare is: 5500\n" ] } ], @@ -212,7 +225,9 @@ "\n", "class Bus(Vehicle):\n", " # Hint: Override fare method to include maintenance charge\n", - " pass\n", + "\n", + " def fare(self):\n", + " return self.capacity * 110 \n", "\n", "school_bus = Bus(\"School Volvo\", 12, 50)\n", "print(\"Total Bus fare is:\", school_bus.fare()) # Expected output: Total Bus fare is: (calculated amount)" @@ -228,7 +243,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -255,7 +270,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -287,7 +302,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -301,9 +316,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.11.7" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }