-
Notifications
You must be signed in to change notification settings - Fork 701
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 #653
base: master
Are you sure you want to change the base?
solution #653
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.
Hello! 😊 It looks like you're making great progress, but there are a couple of critical issues that need to be addressed before we can approve this pull request:
-
Premature Function Termination: In the
shop_trip
function, thereturn
statement inside the loop causes the function to exit entirely if one customer doesn't have enough money. This prevents subsequent customers from being processed. Consider usingcontinue
instead ofreturn
to allow the loop to proceed to the next customer. -
Redundant Attribute Assignment: The
milk
attribute in theCustomer
class is being assigned twice. This redundancy can lead to confusion and should be corrected by removing one of the assignments.
Once these issues are resolved, your code will be in great shape! Keep up the good work, and I look forward to seeing the improvements. 🚀
✨ 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
self.milk = self.product_cart["milk"] | ||
self.milk = self.product_cart["milk"] |
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 milk
attribute is being assigned twice. This is redundant and could lead to confusion. You should remove one of these assignments.
app/main.py
Outdated
else: | ||
print(f"{customer.name} doesn't have enough money " | ||
f"to make a purchase in any shop") | ||
return |
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 return
statement inside the else
block will terminate the shop_trip
function entirely if one customer doesn't have enough money. This means that subsequent customers will not be processed. Consider using continue
instead of return
to skip to the next customer.
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 your submission! 🎉 Your code meets most of the task requirements and constraints, and it's clear you've put in a lot of effort. However, there are a few areas for improvement that could enhance the robustness and clarity of your code:
-
Error Handling: Consider adding error handling for missing keys in dictionaries, such as
shop
,customer
, andperson_data
. This can preventKeyError
exceptions and make your code more robust. Usingdict.get()
with default values or try-except blocks can be helpful. -
Variable Naming: The variable
cheeper_shop
appears to be a typo. Renaming it tocheaper_shop
would improve clarity and correctness. -
Logic Validation: Ensure that calculations, such as
customer.money - min_cost
, correctly reflect the intended logic, including all necessary costs like products and fuel. -
Data Validation: Validate that
customer.car_consumption
is a valid number and thatcustomer.location
andshop.location
are tuples or lists with at least two elements to avoid runtime errors. -
Consistency: Ensure consistency in JSON key naming between files, such as
"FUEL_PRICE"
and"fuel_price"
.
These improvements will not only help you avoid potential errors but also make your code cleaner and more maintainable. Keep up the great work, and continue to learn and grow from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
self.name = customer["name"] | ||
self.product_cart = customer["product_cart"] | ||
self.milk = self.product_cart["milk"] | ||
self.bread = self.product_cart["bread"] | ||
self.butter = self.product_cart["butter"] | ||
self.location = customer["location"] | ||
self.money = customer["money"] | ||
self.car_consumption = customer["car"]["fuel_consumption"] |
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 error handling for missing keys in the customer
dictionary. Using dict.get()
with default values can prevent KeyError
exceptions if any expected key is missing.
person_data = json.load(f) | ||
shops = [Shop(shop) for shop in person_data["shops"]] | ||
customers = [ | ||
Customer(customer) for customer in person_data["customers"] | ||
] | ||
fuel_price = person_data["FUEL_PRICE"] |
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 error handling for missing keys in the person_data
dictionary. This can prevent KeyError
exceptions if any expected key is missing. Using dict.get()
with default values or try-except blocks can be helpful.
customers = user_data["customers"] | ||
shops = user_data["shops"] | ||
for customer in customers: | ||
cheeper_shop = 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 variable name cheeper_shop
seems to be a typo. Consider renaming it to cheaper_shop
for clarity and correctness.
print(f"{customer.name}'s trip " | ||
f"to the {shop.name} costs " | ||
f"{cost}") | ||
min_cost = min(list(cheeper_shop.keys())) |
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 cheeper_shop
is not empty before calling min()
. If it's empty, min()
will raise a ValueError
. Consider adding a check to handle this case.
f"\nTotal cost is {total} dollars" | ||
f"\nSee you again!\n" | ||
f"\n{customer.name} rides home\n" | ||
f"{customer.name} now has {customer.money - min_cost} 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.
The calculation customer.money - min_cost
assumes that min_cost
includes the cost of products and fuel. Ensure that this logic correctly reflects the intended deduction from the customer's money.
self.name = shop["name"] | ||
self.location = shop["location"] | ||
self.products = shop["products"] | ||
self.price_milk = self.products["milk"] | ||
self.price_bread = self.products["bread"] | ||
self.price_butter = self.products["butter"] |
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 error handling for missing keys in the shop
dictionary. Using dict.get()
with default values can prevent KeyError
exceptions if any expected key is missing.
distance = (abs(customer.location[0] - shop.location[0]) | ||
** 2 + abs(customer.location[1] - shop.location[1]) | ||
** 2) ** 0.5 |
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 customer.location
and shop.location
are tuples or lists with at least two elements. If not, accessing these indices will raise an IndexError
.
distance = (abs(customer.location[0] - shop.location[0]) | ||
** 2 + abs(customer.location[1] - shop.location[1]) | ||
** 2) ** 0.5 | ||
cost = ((distance * 2 * customer.car_consumption / 100 * fuel_price) |
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 customer.car_consumption
is a valid number. If it's not set or is invalid, this calculation will raise an error.
No description provided.