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 #1749

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
44 changes: 40 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
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, list_cars: list) -> float:
total_cost = 0
for car in list_cars:
if car.clean_mark < self.clean_power:
total_cost += self.calculate_washing_price(car)
self.wash_single_car(car)
return total_cost

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

def wash_single_car(self, car: Car) -> Car:
if self.clean_power > car.clean_mark:
car.clean_mark = self.clean_power
return car

def rate_service(self, rating: float) -> float:
avg_rating = (self.average_rating * self.count_of_ratings) + rating
self.count_of_ratings += 1
self.average_rating = round(avg_rating / self.count_of_ratings, 1)
Comment on lines +40 to +43

Choose a reason for hiding this comment

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

There is an issue with the calculation of the new average rating in the rate_service method. The expression (self.average_rating * self.count_of_ratings) + rating should be enclosed in parentheses to ensure the correct order of operations. Otherwise, the addition of rating might not be calculated as intended due to operator precedence.

return self.average_rating
Loading