Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution Washing Staiton #1616

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
class Car:
# write your code here
pass
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:
# write your code here
pass
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.wash_single_car(car)
car.clean_mark = self.clean_power
return round(total_income, 1)

def calculate_washing_price(self, car: Car) -> float:
cost = (car.comfort_class * (self.clean_power - car.clean_mark) *
self.average_rating / self.distance_from_city_center)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the calculate_washing_price method, ensure that distance_from_city_center is not zero to avoid division by zero errors. Consider adding a check or handling this case appropriately.

return round(cost, 1)

def wash_single_car(self, car: Car):
return round(self.calculate_washing_price(car), 1)
Comment on lines +29 to +30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wash_single_car method should return a value. Currently, it calls calculate_washing_price and rounds the result, but it should explicitly return this value to ensure the method's purpose is clear.


def rate_service(self, rate: float) -> None:
rate = max(1.0, min(rate, 5.0))
total_ratings = self.count_of_ratings
self.average_rating = round(
(self.average_rating * total_ratings + rate) / (total_ratings + 1), 1)
self.count_of_ratings += 1
Loading