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

Develop #341

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

Develop #341

wants to merge 5 commits into from

Conversation

romkapomka12
Copy link

No description provided.

app/customer.py Outdated
money: int,
car: Car,
product_cart: dict,
customer_location: list

Choose a reason for hiding this comment

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

add additional typehint for list inner objects like list[YOUR_VALUE_TYPE]
for example: list that contains string elements has typehint list[str]

app/customer.py Outdated
products_price = self.get_product_price(shop)
return round(fuel_cost + products_price, 2)

def get_product_price(self, shop: Shop) -> None:

Choose a reason for hiding this comment

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

invalid return typehint

app/customer.py Outdated
Comment on lines 50 to 54
def products_cost(self, product_cart: dict) -> int:
total = 0
for product in product_cart:
total += self.product_cart[product]
return total

Choose a reason for hiding this comment

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

remove this non-callable method

app/customer.py Outdated
+ (shop.location[1] - self.location[1]) ** 2) ** 0.5
)

fuel_cost = \

Choose a reason for hiding this comment

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

use parentheses instead of backslash to wrap the line

app/main.py Outdated
Comment on lines 60 to 61
# if __name__ == "__main__":
# shop_trip()

Choose a reason for hiding this comment

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

remove this test code block

app/shop.py Outdated

class Shop:

def __init__(self, name: str, shop_location: list, products: dict) -> None:

Choose a reason for hiding this comment

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

add additional typehint for list inner objects like list[YOUR_VALUE_TYPE]
for example: list that contains string elements has typehint list[str]

app/main.py Outdated
Comment on lines 7 to 57
def shop_trip() -> None:
with open("app/config.json") as file:
config = json.load(file)

fuel_price = config["FUEL_PRICE"]

customers = [
Customer(name=customer["name"],
product_cart=customer["product_cart"],
customer_location=customer["location"],
money=customer["money"],
car=Car(**customer["car"]))
for customer in config["customers"]
]

shops = [
Shop(name=shop["name"],
shop_location=shop["location"],
products=shop["products"])
for shop in config["shops"]
]
for customer in customers:
cheapest_cost = None
cheapest_shop = None
print(f"{customer.name} has {customer.money} dollars")
for shop in shops:

trip_cost = customer.get_trip_price(fuel_price, shop)

print(f"{customer.name}\'s trip to the "
f"{shop.name} costs {trip_cost}")

if cheapest_cost is None or trip_cost < cheapest_cost:
cheapest_cost = trip_cost
cheapest_shop = shop

if customer.money >= cheapest_cost:
print(f"{customer.name} rides to {cheapest_shop.name}")
customer.location = cheapest_shop.location
customer.money -= cheapest_cost

customer.print_the_purchase_receipt(cheapest_shop)
print(f"Total cost is "
f"{customer.get_product_price(cheapest_shop)} dollars")
print("See you again!\n")

print(f"{customer.name} rides home")
print(f"{customer.name} now has {customer.money} dollars\n")
else:
print(f"{customer.name} doesn't have enough money "
f"to make a purchase in any shop")

Choose a reason for hiding this comment

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

separate your function into a few functions with own logic

app/shop.py Outdated
Comment on lines 5 to 9
def __init__(self,
name: str,
shop_location: list[int, int],
products: dict
) -> None:

Choose a reason for hiding this comment

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

Suggested change
def __init__(self,
name: str,
shop_location: list[int, int],
products: dict
) -> None:
def __init__(
self,
name: str,
shop_location: list[int, int],
products: dict
) -> None:

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