-
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
Develop #341
base: master
Are you sure you want to change the base?
Develop #341
Conversation
app/customer.py
Outdated
money: int, | ||
car: Car, | ||
product_cart: dict, | ||
customer_location: list |
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.
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: |
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.
invalid return typehint
app/customer.py
Outdated
def products_cost(self, product_cart: dict) -> int: | ||
total = 0 | ||
for product in product_cart: | ||
total += self.product_cart[product] | ||
return 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.
remove this non-callable method
app/customer.py
Outdated
+ (shop.location[1] - self.location[1]) ** 2) ** 0.5 | ||
) | ||
|
||
fuel_cost = \ |
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.
use parentheses instead of backslash to wrap the line
app/main.py
Outdated
# if __name__ == "__main__": | ||
# shop_trip() |
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.
remove this test code block
app/shop.py
Outdated
|
||
class Shop: | ||
|
||
def __init__(self, name: str, shop_location: list, products: dict) -> None: |
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.
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
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") |
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.
separate your function into a few functions with own logic
app/shop.py
Outdated
def __init__(self, | ||
name: str, | ||
shop_location: list[int, int], | ||
products: dict | ||
) -> None: |
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.
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: | |
No description provided.