-
Notifications
You must be signed in to change notification settings - Fork 725
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
Develop #673
base: master
Are you sure you want to change the base?
Develop #673
Conversation
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.
Great job on implementing the solution! 🎉 The code meets the task requirements and is well-structured across multiple modules. While there are a few minor issues to address, such as handling cases where a product is not available and ensuring the customer can afford the trip even with exact funds, these do not significantly impact the overall functionality. Keep up the good work and consider these improvements for future projects! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
def calculate_distance(home: list, shop: list) -> float: | ||
return math.sqrt((shop[0] - home[0]) ** 2 + (shop[1] - home[1]) ** 2) |
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.
The calculate_distance
method assumes that both home
and shop
lists have exactly two elements (representing x and y coordinates). It would be safer to validate the length of these lists before performing calculations to avoid potential index errors.
def total_cost(self, shop: Shop, fuel_price: float) -> float: | ||
distance = self.car.calculate_distance(self.location, shop.location) | ||
fuel_cost = self.car.fuel_cost(distance * 2, fuel_price) | ||
product_cost = shop.products_cost(self.client_products) |
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.
The products_cost
method in the Shop
class returns -1 if a product is not available. You should handle this case in the total_cost
method to avoid incorrect calculations.
if 0 < total_cost < best_cost: | ||
best_cost = total_cost | ||
best_shop = shop | ||
if self.money > best_cost: |
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.
The condition if self.money > best_cost
should be if self.money >= best_cost
to ensure the customer can afford the trip even if they have exactly the amount needed.
if product_name in self.products: | ||
total += self.products[product_name] * amount | ||
else: | ||
return -1 |
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.
Returning -1 when a product is not available is a valid approach, but ensure that the calling code handles this case to avoid incorrect calculations or logic errors.
No description provided.