From a86dcd9462573aeadc9ee577151bdafa432edddb Mon Sep 17 00:00:00 2001 From: alega1705 <36694096+alega1705@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:45:21 +0200 Subject: [PATCH 1/3] Solution --- app/main.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index b2d096bd..e0dfb686 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,80 @@ class Car: - # write your code here - pass - + def __init__(self, comfort_class, clean_mark, brand): + self.comfort_class = comfort_class + self.clean_mark = clean_mark + self.brand = brand class CarWashStation: - # write your code here - pass + def __init__(self, distance_from_city_center, clean_power, average_rating, count_of_ratings): + self.distance_from_city_center = distance_from_city_center + self.clean_power = clean_power + self.average_rating = average_rating + self.count_of_ratings = count_of_ratings + + def serve_cars(self, cars): + total_income = 0 + for car in cars: + if car.clean_mark < self.clean_power: + total_income += self.calculate_washing_price(car) + car.clean_mark = self.clean_power + return round(total_income, 1) + + def calculate_washing_price(self, car): + price = (car.comfort_class * (self.clean_power - car.clean_mark) * + self.average_rating) / self.distance_from_city_center + return round(price, 1) + + def wash_single_car(self, car): + if car.clean_mark < self.clean_power: + car.clean_mark = self.clean_power + + def rate_service(self, rating): + self.count_of_ratings += 1 + self.average_rating = round(((self.average_rating * (self.count_of_ratings - 1)) + rating) / self.count_of_ratings, 1) + + +# Example Usage: + +# Create Car objects +bmw = Car(comfort_class=3, clean_mark=3, brand='BMW') +audi = Car(comfort_class=4, clean_mark=9, brand='Audi') + +print(bmw.clean_mark) # 3 + +# Create a CarWashStation object +wash_station = CarWashStation( + distance_from_city_center=5, + clean_power=6, + average_rating=3.5, + count_of_ratings=6 +) + +# Serve cars and calculate income +income = wash_station.serve_cars([bmw, audi]) +print(income) # 6.3 +print(bmw.clean_mark) # 6 + +# Another example where both cars get washed +bmw = Car(comfort_class=3, clean_mark=3, brand='BMW') +audi = Car(comfort_class=4, clean_mark=2, brand='Audi') + +print(bmw.clean_mark) # 3 +print(audi.clean_mark) # 2 + +income = wash_station.serve_cars([bmw, audi]) +print(income) # 17.5 + +print(bmw.clean_mark) # 6 +print(audi.clean_mark) # 6 + +# Calculate washing price for a car +ford = Car(comfort_class=2, clean_mark=1, brand='Ford') +wash_cost = wash_station.calculate_washing_price(ford) +print(wash_cost) # 9.1 + + +wash_station.rate_service(5) + +print(wash_station.average_rating) # 4.0 +print(wash_station.count_of_ratings) # 12 + From c8b6047124e792965117402f7ad1fa4a319ddfdf Mon Sep 17 00:00:00 2001 From: alega1705 <36694096+alega1705@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:52:25 +0200 Subject: [PATCH 2/3] Solution --- app/main.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/app/main.py b/app/main.py index e0dfb686..fa865fcf 100644 --- a/app/main.py +++ b/app/main.py @@ -73,8 +73,89 @@ def rate_service(self, rating): print(wash_cost) # 9.1 +wclass Car: + def __init__(self, comfort_class: int, clean_mark: int, brand: str) -> None: + self.comfort_class = comfort_class + self.clean_mark = clean_mark + self.brand = brand + + +class CarWashStation: + def __init__(self, distance_from_city_center: float, clean_power: int, + average_rating: float, count_of_ratings: int) -> None: + self.distance_from_city_center = distance_from_city_center + self.clean_power = clean_power + self.average_rating = average_rating + self.count_of_ratings = count_of_ratings + + def serve_cars(self, cars: list[Car]) -> float: + total_income = 0 + for car in cars: + if car.clean_mark < self.clean_power: + total_income += self.calculate_washing_price(car) + car.clean_mark = self.clean_power + return round(total_income, 1) + + def calculate_washing_price(self, car: Car) -> float: + price = (car.comfort_class * (self.clean_power - car.clean_mark) * + self.average_rating) / self.distance_from_city_center + return round(price, 1) + + def wash_single_car(self, car: Car) -> None: + if car.clean_mark < self.clean_power: + car.clean_mark = self.clean_power + + def rate_service(self, rating: int) -> None: + self.count_of_ratings += 1 + self.average_rating = round(((self.average_rating * (self.count_of_ratings - 1)) + rating) / self.count_of_ratings, 1) + + +# Example Usage: + +# Create Car objects +bmw = Car(comfort_class=3, clean_mark=3, brand="BMW") +audi = Car(comfort_class=4, clean_mark=9, brand="Audi") + +print(bmw.clean_mark) # 3 + +# Create a CarWashStation object +wash_station = CarWashStation( + distance_from_city_center=5, + clean_power=6, + average_rating=3.5, + count_of_ratings=6 +) + +# Serve cars and calculate income +income = wash_station.serve_cars([bmw, audi]) +print(income) # 6.3 +print(bmw.clean_mark) # 6 + +# Another example where both cars get washed +bmw = Car(comfort_class=3, clean_mark=3, brand="BMW") +audi = Car(comfort_class=4, clean_mark=2, brand="Audi") + +print(bmw.clean_mark) # 3 +print(audi.clean_mark) # 2 + +income = wash_station.serve_cars([bmw, audi]) +print(income) # 17.5 + +print(bmw.clean_mark) # 6 +print(audi.clean_mark) # 6 + +# Calculate washing price for a car +ford = Car(comfort_class=2, clean_mark=1, brand="Ford") +wash_cost = wash_station.calculate_washing_price(ford) +print(wash_cost) # 9.1 + +# Rate the service wash_station.rate_service(5) print(wash_station.average_rating) # 4.0 print(wash_station.count_of_ratings) # 12 +5) + +print(wash_station.average_rating) # 4.0 +print(wash_station.count_of_ratings) # 12 From 19ca26784ac430b09518f4d66367f300b91250c5 Mon Sep 17 00:00:00 2001 From: alega1705 <36694096+alega1705@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:56:10 +0200 Subject: [PATCH 3/3] Update main.py --- app/main.py | 113 ++-------------------------------------------------- 1 file changed, 3 insertions(+), 110 deletions(-) diff --git a/app/main.py b/app/main.py index fa865fcf..f54e3302 100644 --- a/app/main.py +++ b/app/main.py @@ -33,92 +33,13 @@ def rate_service(self, rating): self.average_rating = round(((self.average_rating * (self.count_of_ratings - 1)) + rating) / self.count_of_ratings, 1) -# Example Usage: -# Create Car objects bmw = Car(comfort_class=3, clean_mark=3, brand='BMW') audi = Car(comfort_class=4, clean_mark=9, brand='Audi') -print(bmw.clean_mark) # 3 - -# Create a CarWashStation object -wash_station = CarWashStation( - distance_from_city_center=5, - clean_power=6, - average_rating=3.5, - count_of_ratings=6 -) - -# Serve cars and calculate income -income = wash_station.serve_cars([bmw, audi]) -print(income) # 6.3 -print(bmw.clean_mark) # 6 - -# Another example where both cars get washed -bmw = Car(comfort_class=3, clean_mark=3, brand='BMW') -audi = Car(comfort_class=4, clean_mark=2, brand='Audi') - -print(bmw.clean_mark) # 3 -print(audi.clean_mark) # 2 - -income = wash_station.serve_cars([bmw, audi]) -print(income) # 17.5 - -print(bmw.clean_mark) # 6 -print(audi.clean_mark) # 6 - -# Calculate washing price for a car -ford = Car(comfort_class=2, clean_mark=1, brand='Ford') -wash_cost = wash_station.calculate_washing_price(ford) -print(wash_cost) # 9.1 - - -wclass Car: - def __init__(self, comfort_class: int, clean_mark: int, brand: str) -> None: - self.comfort_class = comfort_class - self.clean_mark = clean_mark - self.brand = brand +print(bmw.clean_mark) -class CarWashStation: - def __init__(self, distance_from_city_center: float, clean_power: int, - average_rating: float, count_of_ratings: int) -> None: - self.distance_from_city_center = distance_from_city_center - self.clean_power = clean_power - self.average_rating = average_rating - self.count_of_ratings = count_of_ratings - - def serve_cars(self, cars: list[Car]) -> float: - total_income = 0 - for car in cars: - if car.clean_mark < self.clean_power: - total_income += self.calculate_washing_price(car) - car.clean_mark = self.clean_power - return round(total_income, 1) - - def calculate_washing_price(self, car: Car) -> float: - price = (car.comfort_class * (self.clean_power - car.clean_mark) * - self.average_rating) / self.distance_from_city_center - return round(price, 1) - - def wash_single_car(self, car: Car) -> None: - if car.clean_mark < self.clean_power: - car.clean_mark = self.clean_power - - def rate_service(self, rating: int) -> None: - self.count_of_ratings += 1 - self.average_rating = round(((self.average_rating * (self.count_of_ratings - 1)) + rating) / self.count_of_ratings, 1) - - -# Example Usage: - -# Create Car objects -bmw = Car(comfort_class=3, clean_mark=3, brand="BMW") -audi = Car(comfort_class=4, clean_mark=9, brand="Audi") - -print(bmw.clean_mark) # 3 - -# Create a CarWashStation object wash_station = CarWashStation( distance_from_city_center=5, clean_power=6, @@ -126,36 +47,8 @@ def rate_service(self, rating: int) -> None: count_of_ratings=6 ) -# Serve cars and calculate income -income = wash_station.serve_cars([bmw, audi]) -print(income) # 6.3 -print(bmw.clean_mark) # 6 - -# Another example where both cars get washed -bmw = Car(comfort_class=3, clean_mark=3, brand="BMW") -audi = Car(comfort_class=4, clean_mark=2, brand="Audi") - -print(bmw.clean_mark) # 3 -print(audi.clean_mark) # 2 income = wash_station.serve_cars([bmw, audi]) -print(income) # 17.5 - +print(income) # 6.3 print(bmw.clean_mark) # 6 -print(audi.clean_mark) # 6 - -# Calculate washing price for a car -ford = Car(comfort_class=2, clean_mark=1, brand="Ford") -wash_cost = wash_station.calculate_washing_price(ford) -print(wash_cost) # 9.1 - -# Rate the service -wash_station.rate_service(5) - -print(wash_station.average_rating) # 4.0 -print(wash_station.count_of_ratings) # 12 -5) - -print(wash_station.average_rating) # 4.0 -print(wash_station.count_of_ratings) # 12 - +