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

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

solution #653

wants to merge 3 commits into from

Conversation

sashasyrota
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.


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:

  1. Premature Function Termination: In the shop_trip function, the return 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 using continue instead of return to allow the loop to proceed to the next customer.

  2. Redundant Attribute Assignment: The milk attribute in the Customer 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
Comment on lines 5 to 6
self.milk = self.product_cart["milk"]
self.milk = self.product_cart["milk"]

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
Comment on lines 25 to 28
else:
print(f"{customer.name} doesn't have enough money "
f"to make a purchase in any shop")
return

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.

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 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:

  1. Error Handling: Consider adding error handling for missing keys in dictionaries, such as shop, customer, and person_data. This can prevent KeyError exceptions and make your code more robust. Using dict.get() with default values or try-except blocks can be helpful.

  2. Variable Naming: The variable cheeper_shop appears to be a typo. Renaming it to cheaper_shop would improve clarity and correctness.

  3. Logic Validation: Ensure that calculations, such as customer.money - min_cost, correctly reflect the intended logic, including all necessary costs like products and fuel.

  4. Data Validation: Validate that customer.car_consumption is a valid number and that customer.location and shop.location are tuples or lists with at least two elements to avoid runtime errors.

  5. 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! ✨

Comment on lines +3 to +10
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"]

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.

Comment on lines +12 to +17
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"]

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()

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()))

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")

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.

Comment on lines +3 to +8
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"]

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.

Comment on lines +10 to +12
distance = (abs(customer.location[0] - shop.location[0])
** 2 + abs(customer.location[1] - shop.location[1])
** 2) ** 0.5

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)

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.

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