Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
omerlenko committed Oct 31, 2024
1 parent 1a61346 commit ec1c3c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions app/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def calculate_travel_cost(
return round(l_per_km * distance * fuel_price * 2, 2)

def calculate_cart_cost(self, shop: Shop) -> int | float:
cart_cost = 0
for item in self.product_cart:
cart_cost += self.product_cart[item] * shop.products[item]
return cart_cost
if shop.products:
cart_cost = 0
for item in self.product_cart:
cart_cost += self.product_cart[item] * shop.products[item]
return cart_cost
return 0

def calculate_total_cost(
self,
Expand Down
4 changes: 2 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def shop_trip() -> None:
for customer in customers:
print(f"{customer.name} has {customer.money} dollars")

cheapest_shop = [None, 0]
cheapest_shop = [None, float("inf")]
for shop in shops:
total_cost = customer.calculate_total_cost(fuel_price, shop)
if total_cost < cheapest_shop[1] or cheapest_shop[1] == 0:
if total_cost < cheapest_shop[1]:
cheapest_shop[0] = shop
cheapest_shop[1] = total_cost
print(f"{customer.name}'s trip to "
Expand Down

0 comments on commit ec1c3c5

Please sign in to comment.