diff --git a/lab-oop_in_python.ipynb b/lab-oop_in_python.ipynb index 3142c5e..ea9bc42 100644 --- a/lab-oop_in_python.ipynb +++ b/lab-oop_in_python.ipynb @@ -30,20 +30,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "250 125000\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(250, 125000) # 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)" + "print(modelX.max_speed, modelX.mileage)\n", + " # Expected output: (value of max_speed, value of mileage)" ] }, { @@ -56,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -87,25 +98,31 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 64, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n" + "\n", + "Bus Type: School Volvo, Max Speed: 180, Mileage: 12\n" ] } ], "source": [ "# Your code here\n", "class Bus(Vehicle):\n", - " pass\n", - "\n", + " def __init__(self, vehicule_type, max_speed, mileage):\n", + " super().__init__(max_speed, mileage)\n", + " self.vehicle_type = vehicule_type\n", + " def __str__(self):\n", + " return f\"Bus Type: {self.vehicle_type}, Max Speed: {self.max_speed}, Mileage: {self.mileage}\" \n", + " \n", "# Example instantiation\n", - "school_bus = Bus()\n", - "print(type(school_bus)) # Expected output: " + "school_bus = Bus(\"School Volvo\", 180, 12)\n", + "print(type(school_bus)) # Expected output: \n", + "print(school_bus)" ] }, { @@ -118,14 +135,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 74, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Base fare\n" + "Base farewith extra charge\n" ] } ], @@ -137,7 +154,9 @@ "\n", "class Bus(Vehicle):\n", " # Hint: Override fare method to include extra charges\n", - " pass\n", + " def fare(self):\n", + " base_fare = super().fare()\n", + " return super().fare() + \"with extra charge\"\n", "\n", "school_bus = Bus()\n", "print(school_bus.fare()) # Expected output: \"Base fare with extra charge\"" @@ -153,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 75, "metadata": {}, "outputs": [ { @@ -188,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 76, "metadata": {}, "outputs": [ { @@ -228,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 77, "metadata": {}, "outputs": [ { @@ -255,7 +274,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 78, "metadata": {}, "outputs": [ { @@ -287,7 +306,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "base", "language": "python", "name": "python3" }, @@ -301,7 +320,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.11.5" } }, "nbformat": 4,