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

Develop #673

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Develop #673

wants to merge 3 commits into from

Conversation

B0hdanR
Copy link

@B0hdanR B0hdanR commented Dec 24, 2024

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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! ✨

Comment on lines +13 to +14
def calculate_distance(home: list, shop: list) -> float:
return math.sqrt((shop[0] - home[0]) ** 2 + (shop[1] - home[1]) ** 2)

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)

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:

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants