-
Notifications
You must be signed in to change notification settings - Fork 696
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
base: master
Are you sure you want to change the base?
Solution #649
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.
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:
-
Customer's Financial State: The
ride_home
method in theCustomer
class does not update themoney
attribute after spending money. This is crucial for maintaining an accurate financial state for the customer. -
Product Handling in
Shop
Class: Theprint_check
method assumes certain products are always present, which can lead to errors if they are not. Additionally, theself.products.get(product)
expression may returnNone
, causing aTypeError
. Please ensure these cases are handled properly. -
Efficiency and Error Handling: In the
shop_trip
function, consider storing the result ofmin(trip_cost_dict)
in a variable to avoid recalculating it. Also, ensure there's a check for an emptytrip_cost_dict
to prevent aValueError
.
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
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") |
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.
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): |
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 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
total = min(trip_cost_dict) | ||
current_shop = trip_cost_dict[min(trip_cost_dict)] |
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 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) |
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.
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) |
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 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
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") |
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 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.
No description provided.