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

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

Conversation

AndrewChugreev
Copy link

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.

Thank you for your hard work on this project! While your code meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Customer's Financial State: The ride_home method in the Customer class does not update the money attribute after spending money. This is crucial for maintaining an accurate financial state for the customer.

  2. Product Handling in Shop Class: The print_check method assumes certain products are always present, which can lead to errors if they are not. Additionally, the self.products.get(product) expression may return None, causing a TypeError. Please ensure these cases are handled properly.

  3. Efficiency and Error Handling: In the shop_trip function, consider storing the result of min(trip_cost_dict) in a variable to avoid recalculating it. Also, ensure there's a check for an empty trip_cost_dict to prevent a ValueError.

Addressing these issues will significantly improve the functionality and robustness of your code. Keep up the great work, and I'm confident you'll nail it with these adjustments! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

app/customer.py Outdated
Comment on lines 26 to 28
def ride_home(self, spend_money: float) -> None:
print(f"{self.name} rides home")
print(f"{self.name} now has {self.money - spend_money} dollars\n")

Choose a reason for hiding this comment

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

In the ride_home method, the money attribute is not updated after spending money. You should update self.money by subtracting spend_money from it to reflect the current financial state of the customer.

app/main.py Outdated
total += round((products_cost + fuel_for_shop * 2), 2)
trip_cost_dict[total] = shop
print(f"{customer.name}'s trip to the {shop.name} costs {total}")
if customer.money < min(trip_cost_dict):

Choose a reason for hiding this comment

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

The condition if customer.money < min(trip_cost_dict): assumes that trip_cost_dict is not empty. Ensure that there is a check to handle the case where trip_cost_dict might be empty, which could lead to a ValueError when calling min().

app/main.py Outdated
Comment on lines 54 to 55
total = min(trip_cost_dict)
current_shop = trip_cost_dict[min(trip_cost_dict)]

Choose a reason for hiding this comment

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

The logic for selecting the shop with the minimum cost is correct, but it would be more efficient to store the result of min(trip_cost_dict) in a variable and reuse it in line 55 to avoid recalculating it.

app/main.py Outdated
current_shop = trip_cost_dict[min(trip_cost_dict)]
print(f"{customer.name} rides to {current_shop.name}\n")
current_shop.print_check(customer)
customer.ride_home(total)

Choose a reason for hiding this comment

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

Ensure that the ride_home method updates the customer's money correctly, as previously noted in the Customer class review. This will ensure that the customer's financial state is accurately reflected after the trip.

product_cart = customer.product_cart
product_cost = 0
for product, qty in product_cart.items():
product_cost += qty * self.products.get(product)

Choose a reason for hiding this comment

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

The expression self.products.get(product) may return None if the product is not found in the shop's inventory. This could lead to a TypeError when multiplying None by qty. Consider providing a default value (e.g., 0) to avoid this issue.

app/shop.py Outdated
Comment on lines 29 to 43
milk = customer.product_cart.get("milk")
print(f"{milk} "
f"milks for "
f"{milk * self.products.get('milk')}"
f" dollars")
bread = customer.product_cart.get("bread")
print(f"{bread} "
f"breads for "
f"{round(bread * self.products.get('bread'))}"
f" dollars")
butter = customer.product_cart.get("butter")
print(f"{butter}"
f" butters for "
f"{butter * self.products.get('butter')}"
f" dollars")

Choose a reason for hiding this comment

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

The print_check method assumes that 'milk', 'bread', and 'butter' are always present in the customer's cart. If any of these products are not in the cart, None will be returned, leading to potential errors. Consider checking if the product exists in the cart before attempting to access its quantity and price.

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