-
Notifications
You must be signed in to change notification settings - Fork 730
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 #414
base: master
Are you sure you want to change the base?
Develop #414
Conversation
final submit has failed git auto check, please fix |
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.
test failed, please fix
9ae6c3c
to
636b6f2
Compare
def from_dict(cls_dict: dict) -> Car: | ||
new_car = Car() | ||
for key in cls_dict: | ||
setattr(new_car, key, cls_dict[key]) | ||
return new_car |
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.
To create instances you can just use **
to unpack and list comprehension. It will look much more readable, and you won't need to create FromDict class. Also think about method and parameter names to increase readability
And this method better to be classmethod, not static
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.
Same everywhere
brand: str = "", | ||
fuel_consumption: int | float = 0.0) -> 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.
Do you really want to accept creating cars with "" brand and 0.0 fuel_consumption?
Skip adding default values here, fix everywhere
customers = [Customer.from_dict(customer) | ||
for customer in config["customers"]] | ||
shops = [Shop.from_dict(shop) | ||
for shop in config["shops"]] |
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.
You can just use unpacking, that I mentioned in previoius comments
util.calculate_trip_cost(fuel_price, | ||
customer, | ||
shops[closest_shop]), | ||
2 |
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.
this 2
looks really lonely here (
def shop_trip() -> None: | ||
config = util.parse_json("app/config.json") | ||
|
||
fuel_price = config["FUEL_PRICE"] | ||
customers = [Customer.from_dict(customer) | ||
for customer in config["customers"]] | ||
shops = [Shop.from_dict(shop) | ||
for shop in config["shops"]] | ||
|
||
for customer in customers: | ||
print(f"{customer.name} has {customer.money} dollars") | ||
|
||
closest_shop = 0 | ||
min_cost = 100 | ||
for index, shop in enumerate(shops): | ||
trip_cost = round( | ||
util.calculate_trip_cost(fuel_price, customer, shop), | ||
2 | ||
) | ||
|
||
print(f"{customer.name}'s trip to the" | ||
f" {shop.name} costs {trip_cost}") | ||
|
||
if trip_cost < min_cost: | ||
min_cost = trip_cost | ||
closest_shop = index | ||
|
||
if customer.money < min_cost: | ||
print(f"{customer.name} " | ||
f"doesn't have enough money to make a purchase in any shop") | ||
continue | ||
|
||
print(f"{customer.name} rides to {shops[closest_shop].name}\n") | ||
shops[closest_shop].print_receipt(customer) | ||
customer.money -= round( | ||
util.calculate_trip_cost(fuel_price, | ||
customer, | ||
shops[closest_shop]), | ||
2 | ||
) | ||
|
||
print(f"{customer.name} rides home") | ||
print(f"{customer.name} now has {customer.money} 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.
Consider split into methods
No description provided.