From 03580442927e7d8aba1ddc3825b6cd35c3fb600c Mon Sep 17 00:00:00 2001 From: Jeanlebaptist Date: Wed, 23 Jul 2025 19:09:42 +0200 Subject: [PATCH 1/3] lap py OOP --- lab-oop_in_python.ipynb | 50 +++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/lab-oop_in_python.ipynb b/lab-oop_in_python.ipynb index 3142c5e..7b00bd3 100644 --- a/lab-oop_in_python.ipynb +++ b/lab-oop_in_python.ipynb @@ -30,20 +30,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "240 15000\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(240, 15000)\n", "\n", "# Print attributes\n", - "print(modelX.max_speed, modelX.mileage) # Expected output: (value of max_speed, value of mileage)" + "print(modelX.max_speed, modelX.mileage) # Output: 240 15000\n" ] }, { @@ -56,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -74,7 +83,9 @@ "\n", "# Example instantiation\n", "my_vehicle = Vehicle()\n", - "print(type(my_vehicle)) # Expected output: " + "\n", + "# Print the type of the object\n", + "print(type(my_vehicle)) # Expected output: \n" ] }, { @@ -87,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -100,12 +111,17 @@ ], "source": [ "# Your code here\n", + "class Vehicle:\n", + " pass\n", + "\n", "class Bus(Vehicle):\n", " pass\n", "\n", "# Example instantiation\n", "school_bus = Bus()\n", - "print(type(school_bus)) # Expected output: " + "\n", + "# Check the type\n", + "print(type(school_bus)) # Output: \n" ] }, { @@ -118,7 +134,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -153,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -188,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -228,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -255,7 +271,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -287,7 +303,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -301,7 +317,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.13.5" } }, "nbformat": 4, From c8ebb487bee3ea6c24fcbd6f2b4fd63aa258b608 Mon Sep 17 00:00:00 2001 From: Jeanlebaptist Date: Fri, 25 Jul 2025 14:29:26 +0200 Subject: [PATCH 2/3] lab oop in python --- lab-oop_in_python.ipynb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lab-oop_in_python.ipynb b/lab-oop_in_python.ipynb index 7b00bd3..2ed7d2b 100644 --- a/lab-oop_in_python.ipynb +++ b/lab-oop_in_python.ipynb @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -65,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -98,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -134,7 +134,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -169,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -204,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -244,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -271,7 +271,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 32, "metadata": {}, "outputs": [ { From 5b40c0fd58a305be17d15d386e12f352385ca5ac Mon Sep 17 00:00:00 2001 From: Jeanlebaptist Date: Fri, 25 Jul 2025 14:48:13 +0200 Subject: [PATCH 3/3] lab oop in ython --- lab-oop_in_python.ipynb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lab-oop_in_python.ipynb b/lab-oop_in_python.ipynb index 2ed7d2b..150e9f2 100644 --- a/lab-oop_in_python.ipynb +++ b/lab-oop_in_python.ipynb @@ -134,14 +134,14 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Base fare\n" + "Base fare with extra charge\n" ] } ], @@ -152,11 +152,12 @@ " return \"Base fare\"\n", "\n", "class Bus(Vehicle):\n", - " # Hint: Override fare method to include extra charges\n", - " pass\n", + " def fare(self):\n", + " return \"Base fare with extra charge\"\n", "\n", + "# Example usage\n", "school_bus = Bus()\n", - "print(school_bus.fare()) # Expected output: \"Base fare with extra charge\"" + "print(school_bus.fare()) # Output: Base fare with extra charge\n" ] }, { @@ -204,14 +205,14 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Total Bus fare is: 5000\n" + "Total Bus fare is: 5500.0\n" ] } ], @@ -227,11 +228,14 @@ " return self.capacity * 100\n", "\n", "class Bus(Vehicle):\n", - " # Hint: Override fare method to include maintenance charge\n", - " pass\n", + " def fare(self):\n", + " base_fare = super().fare() # Call parent class fare()\n", + " maintenance_charge = base_fare * 0.10\n", + " return base_fare + maintenance_charge\n", "\n", + "# Example usage\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)" + "print(\"Total Bus fare is:\", school_bus.fare()) # Output: 5500.0\n" ] }, {