From 9d40bf45a83cde8e0265b579b52dd3eaef38363a Mon Sep 17 00:00:00 2001 From: MoTalha88 Date: Mon, 25 Nov 2024 19:02:46 -0500 Subject: [PATCH 1/2] updated file --- Truck.py | 26 ++++++++++++++++++++++++-- Vehicle.py | 3 +++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Truck.py b/Truck.py index 44773a9..06abe5f 100644 --- a/Truck.py +++ b/Truck.py @@ -1,5 +1,3 @@ -from Vehicle import Vehicle - class Truck(Vehicle): def __init__(self, brand, model, year, max_load): super().__init__(brand, model, year) @@ -12,3 +10,27 @@ def display_info(self): def honk(self): """Specific implementation for a truck.""" return "HOOOOONK!" + + def load_cargo(self, weight): + """ + Simulates loading cargo onto the truck. + :param weight: Weight of the cargo in tons. + :return: Message indicating whether the cargo was successfully loaded. + """ + if weight <= self.max_load: + return f"Successfully loaded {weight} tons of cargo." + else: + return f"Cannot load {weight} tons. Exceeds max load of {self.max_load} tons." + + def calculate_mileage(self, fuel, distance): + """ + Calculates mileage based on fuel consumption and distance traveled. + :param fuel: Amount of fuel consumed in liters. + :param distance: Distance traveled in kilometers. + :return: Mileage (km/l). + """ + if fuel > 0: + mileage = distance / fuel + return f"The truck's mileage is {mileage:.2f} km/l." + else: + return "Fuel consumption must be greater than 0 to calculate mileage." diff --git a/Vehicle.py b/Vehicle.py index 260f28e..886997e 100644 --- a/Vehicle.py +++ b/Vehicle.py @@ -17,3 +17,6 @@ def fuel_up(self): def brake(self): print("Braking the car.") + + def mileage(self): + print("high milage") \ No newline at end of file From 10f126638c10f1aee1bb5dd58ee240f7e35ddafc Mon Sep 17 00:00:00 2001 From: MoTalha88 Date: Mon, 25 Nov 2024 20:01:19 -0500 Subject: [PATCH 2/2] updated file --- Car update.py | 24 ++++++++++++++++++++++++ Child class.ipynb | 0 Updated car class.py | 24 ++++++++++++++++++++++++ Vehicle.py | 7 +++++-- usage.ipynb | 30 ++++++++++++++++++++++++++---- 5 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 Car update.py create mode 100644 Child class.ipynb create mode 100644 Updated car class.py diff --git a/Car update.py b/Car update.py new file mode 100644 index 0000000..d12c70c --- /dev/null +++ b/Car update.py @@ -0,0 +1,24 @@ +class Car(Vehicle): + def __init__(self, brand, model, year, seats, fuel_type): + super().__init__(brand, model, year) + self.seats = seats # Number of seats in the car + self.fuel_type = fuel_type # Type of fuel (e.g., petrol, diesel, electric) + + def display_info(self): + """Override the parent class method for a Car.""" + return f"Car: {self._brand} {self._model} ({self._year}), Seats: {self.seats}, Fuel: {self.fuel_type}" + + def play_music(self): + """Simulates playing music in the car.""" + return "Playing your favorite music playlist!" + + def activate_air_conditioner(self): + """Simulates turning on the air conditioner.""" + return "Air conditioner activated. Enjoy your ride!" + + def check_fuel(self): + """Checks the fuel type and returns a message.""" + if self.fuel_type.lower() == "electric": + return "The car is fully charged." + else: + return f"Fuel type: {self.fuel_type}. Please ensure the tank is full." diff --git a/Child class.ipynb b/Child class.ipynb new file mode 100644 index 0000000..e69de29 diff --git a/Updated car class.py b/Updated car class.py new file mode 100644 index 0000000..d12c70c --- /dev/null +++ b/Updated car class.py @@ -0,0 +1,24 @@ +class Car(Vehicle): + def __init__(self, brand, model, year, seats, fuel_type): + super().__init__(brand, model, year) + self.seats = seats # Number of seats in the car + self.fuel_type = fuel_type # Type of fuel (e.g., petrol, diesel, electric) + + def display_info(self): + """Override the parent class method for a Car.""" + return f"Car: {self._brand} {self._model} ({self._year}), Seats: {self.seats}, Fuel: {self.fuel_type}" + + def play_music(self): + """Simulates playing music in the car.""" + return "Playing your favorite music playlist!" + + def activate_air_conditioner(self): + """Simulates turning on the air conditioner.""" + return "Air conditioner activated. Enjoy your ride!" + + def check_fuel(self): + """Checks the fuel type and returns a message.""" + if self.fuel_type.lower() == "electric": + return "The car is fully charged." + else: + return f"Fuel type: {self.fuel_type}. Please ensure the tank is full." diff --git a/Vehicle.py b/Vehicle.py index 886997e..c11906a 100644 --- a/Vehicle.py +++ b/Vehicle.py @@ -13,10 +13,13 @@ def honk(self): return "Beep beep!" def fuel_up(self): + """Simulates fueling the vehicle.""" return "Full tank" def brake(self): - print("Braking the car.") + """Simulates braking.""" + return "Braking the vehicle." def mileage(self): - print("high milage") \ No newline at end of file + """Provides general information about mileage.""" + return "High mileage!" diff --git a/usage.ipynb b/usage.ipynb index f3a90ee..d069e4d 100644 --- a/usage.ipynb +++ b/usage.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -27,6 +27,17 @@ "Meep meep!\n", "HOOOOONK!\n" ] + }, + { + "ename": "AttributeError", + "evalue": "'Truck' object has no attribute 'mileage'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[13], line 12\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[38;5;28mprint\u001b[39m(motorcycle\u001b[38;5;241m.\u001b[39mhonk())\n\u001b[0;32m 11\u001b[0m \u001b[38;5;28mprint\u001b[39m(truck\u001b[38;5;241m.\u001b[39mhonk())\n\u001b[1;32m---> 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(truck\u001b[38;5;241m.\u001b[39mmileage())\n", + "\u001b[1;31mAttributeError\u001b[0m: 'Truck' object has no attribute 'mileage'" + ] } ], "source": [ @@ -40,8 +51,19 @@ "\n", "print(car.honk())\n", "print(motorcycle.honk())\n", - "print(truck.honk())" + "print(truck.honk())\n", + "\n", + "\n", + "\n", + "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -60,7 +82,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.5" + "version": "3.12.4" } }, "nbformat": 4,