-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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' #1859
Open
DanylDolgii
wants to merge
1
commit into
mate-academy:master
Choose a base branch
from
DanylDolgii:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
'Solution' #1859
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,87 @@ | ||
class Car: | ||
# write your code here | ||
pass | ||
def __init__( | ||
self, comfort_class: int, clean_mark: int, brand: str | ||
) -> None: | ||
|
||
if not (1 <= comfort_class <= 7): | ||
raise ValueError( | ||
"comfort_class must be between 1 and 7" | ||
) | ||
if not (1 <= clean_mark <= 10): | ||
raise ValueError( | ||
"clean_mark must be between 1 and 10" | ||
) | ||
if not isinstance(brand, str): | ||
raise TypeError("brand must be a string") | ||
|
||
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: | ||
if not (1.0 <= distance_from_city_center <= 10.0): | ||
raise ValueError( | ||
"distance_from_city_center must be between 1.0 and 10.0" | ||
) | ||
if not (1 <= clean_power <= 10): | ||
raise ValueError( | ||
"clean_power must be between 1 and 10" | ||
) | ||
if not (1.0 <= average_rating <= 5.0): | ||
raise ValueError( | ||
"average_rating must be between 1.0 and 5.0" | ||
) | ||
if not isinstance(count_of_ratings, int) or count_of_ratings < 0: | ||
raise ValueError( | ||
"count_of_ratings must be a non-negative integer" | ||
) | ||
|
||
self.distance_from_city_center = distance_from_city_center | ||
self.clean_power = clean_power | ||
self.average_rating = round(average_rating, 1) | ||
self.count_of_ratings = count_of_ratings | ||
|
||
def serve_cars(self, cars: list) -> float: | ||
"""Wash cars with clean_mark < clean_power and return total income.""" | ||
total_income = 0.0 | ||
for car in cars: | ||
if car.clean_mark < self.clean_power: | ||
total_income += self.calculate_washing_price(car) | ||
self.wash_single_car(car) | ||
return round(total_income, 1) | ||
|
||
def calculate_washing_price(self, car: Car) -> float: | ||
"""Calculate the cost for washing a single car.""" | ||
return round( | ||
( | ||
car.comfort_class | ||
* (self.clean_power - car.clean_mark) | ||
* self.average_rating | ||
/ self.distance_from_city_center | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although the current validation prevents |
||
), | ||
1, | ||
) | ||
|
||
def wash_single_car(self, car: Car) -> None: | ||
"""Wash a single car by updating its clean_mark.""" | ||
if car.clean_mark < self.clean_power: | ||
car.clean_mark = self.clean_power | ||
|
||
def rate_service(self, new_rating: float) -> None: | ||
"""Add a new rating and update the average rating.""" | ||
if not (1.0 <= new_rating <= 5.0): | ||
raise ValueError( | ||
"Rating must be between 1.0 and 5.0" | ||
) | ||
|
||
total_rating = self.average_rating * self.count_of_ratings + new_rating | ||
self.count_of_ratings += 1 | ||
self.average_rating = round(total_rating / self.count_of_ratings, 1) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to ensure that the
cars
parameter is a list ofCar
objects. This will prevent runtime errors if the list contains non-Car objects.