diff --git a/lab-oop_in_python.ipynb b/lab-oop_in_python.ipynb index 3142c5e..35b9dc6 100644 --- a/lab-oop_in_python.ipynb +++ b/lab-oop_in_python.ipynb @@ -32,18 +32,26 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "200 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(200, 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)" ] }, { @@ -56,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -68,13 +76,12 @@ } ], "source": [ - "# Your code here\n", "class Vehicle:\n", " pass\n", "\n", "# Example instantiation\n", "my_vehicle = Vehicle()\n", - "print(type(my_vehicle)) # Expected output: " + "print(type(my_vehicle))" ] }, { @@ -87,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -99,13 +106,12 @@ } ], "source": [ - "# Your code here\n", "class Bus(Vehicle):\n", " pass\n", "\n", "# Example instantiation\n", "school_bus = Bus()\n", - "print(type(school_bus)) # Expected output: " + "print(type(school_bus))" ] }, { @@ -118,29 +124,28 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Base fare\n" + "Base fare with extra charge\n" ] } ], "source": [ - "# Your code here\n", "class Vehicle:\n", " def fare(self):\n", " 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 super().fare() + \" with extra charge\"\n", "\n", "school_bus = Bus()\n", - "print(school_bus.fare()) # Expected output: \"Base fare with extra charge\"" + "print(school_bus.fare())" ] }, { @@ -153,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -165,17 +170,17 @@ } ], "source": [ - "# Your code here\n", "class Vehicle:\n", - " color = \"White\" # Hint: Define color as a class attribute\n", + " color = \"White\" # Class attribute\n", "\n", " def __init__(self, name, max_speed, mileage):\n", " self.name = name\n", " self.max_speed = max_speed\n", " self.mileage = mileage\n", "\n", + "# Example instantiation\n", "school_bus = Vehicle(\"School Volvo\", 180, 12)\n", - "print(school_bus.color) # Expected output: \"White\"" + "print(school_bus.color)" ] }, { @@ -188,19 +193,18 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Total Bus fare is: 5000\n" + "Total Bus fare is: 5500.0\n" ] } ], "source": [ - "# Your code here\n", "class Vehicle:\n", " def __init__(self, name, mileage, capacity):\n", " self.name = name\n", @@ -211,11 +215,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()\n", + " maintenance_charge = base_fare * 0.10 # 10% extra charge\n", + " return base_fare + maintenance_charge\n", "\n", + "# Example instantiation\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())" ] }, { @@ -228,7 +235,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -240,9 +247,8 @@ } ], "source": [ - "# Your code here\n", "school_bus = Bus(\"School Volvo\", 12, 50)\n", - "print(type(school_bus)) # Expected output: " + "print(type(school_bus))" ] }, { @@ -255,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -267,8 +273,7 @@ } ], "source": [ - "# Your code here\n", - "print(isinstance(school_bus, Vehicle)) # Expected output: True or False based on inheritance" + "print(isinstance(school_bus, Vehicle))" ] }, { @@ -287,7 +292,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "base", "language": "python", "name": "python3" }, @@ -301,7 +306,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.11.5" } }, "nbformat": 4,