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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
66c1d22
py-shop-trip(1)
ostboiko Oct 4, 2023
2845fba
py-shop-trip
ostboiko Oct 5, 2023
ee880d7
py-shop-trip(1)
ostboiko Oct 7, 2023
58f736c
py-shop-trip(2)
ostboiko Oct 8, 2023
799c93c
fixed_file
ostboiko Oct 8, 2023
8286c63
fixed_file((car.py) and (customer.py))
ostboiko Oct 9, 2023
397e1d3
fixed_file((car.py) and (customer.py))
ostboiko Oct 11, 2023
66da35b
fixed_file((car.py) and (customer.py))
ostboiko Oct 11, 2023
c9fc16e
fixed_file((car.py) and (customer.py))
ostboiko Oct 11, 2023
2f1a854
py-shop-trip
ostboiko Oct 12, 2023
951193f
py-shop-trip(2)
ostboiko Oct 15, 2023
bdb77d1
py-shop-trip(3)
ostboiko Oct 18, 2023
8a86975
py-shop-trip
ostboiko Oct 30, 2023
780f88b
py-shop-trip
ostboiko Nov 2, 2023
9137b69
py-shop-trip
ostboiko Nov 3, 2023
4467b99
py-shop-trip(not fixed)
ostboiko Nov 4, 2023
6eae346
py-shop-trip(Endlich)
ostboiko Nov 5, 2023
8d421d0
py-shop-trip(Endlich)
ostboiko Nov 6, 2023
cefadac
py-shop-trip(1)
ostboiko Nov 8, 2023
a00f990
py-shop-trip(1 fixed)
ostboiko Nov 8, 2023
04df98b
py-shop-trip(finish())
ostboiko Nov 11, 2023
a1c3144
py-shop-trip(finish(1))
ostboiko Nov 11, 2023
ce7d06f
py-shop-trip(finish(2))
ostboiko Nov 11, 2023
ae1ddc5
py-shop-trip(finish(2))
ostboiko Nov 11, 2023
e627836
py-shop-trip(finish(fixed))
ostboiko Nov 11, 2023
606eb10
py-shop-trip(finish(fixed1))
ostboiko Nov 11, 2023
51c5e44
py-shop-trip(finish(fixed 1))
ostboiko Nov 11, 2023
fb41d1f
py-shop-trip(finish(fixed 2))
ostboiko Nov 11, 2023
573b1cf
py-shop-trip(finish(fixed 2))
ostboiko Nov 11, 2023
df6839a
py-shop-trip(finish(fixed 3))
ostboiko Nov 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md

Choose a reason for hiding this comment

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

This file was not fixed

Choose a reason for hiding this comment

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

Restore changes on it

Choose a reason for hiding this comment

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

Please restore this file!

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before starting.

You want to create an application that helps customers to choose the cheapest


#You want to create an application that helps customers to choose the cheapest

Choose a reason for hiding this comment

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

Why do you change this?

trip for the products.

There is `config.json` file that contains:
Expand Down Expand Up @@ -141,6 +143,3 @@ You design application architecture by yourself, but there are some rules:

Distance between customer and shop is a distance between their locations in km.
Round printed value to two decimal places.


### Note: Check your code using this [checklist](checklist.md) before pushing your solution.

Choose a reason for hiding this comment

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

Restore this code

Empty file added app/__init__.py
Empty file.
1 change: 1 addition & 0 deletions app/car.py

Choose a reason for hiding this comment

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

The file is still not fixed. Try to recreate the file and rewrite the code.

Choose a reason for hiding this comment

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

File not fixed

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from typing import Dict, Anyclass Car: def __init__( self, info: Dict[str, Any], fuel_price: float, ) -> str: self.brand = info["brand"] self.fuel_consumption = info["fuel_consumption"] self.fuel_price = float(fuel_price)
Expand Down
1 change: 1 addition & 0 deletions app/customer.py

Choose a reason for hiding this comment

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

The file is still not fixed. Try to recreate the file and rewrite the code.

Choose a reason for hiding this comment

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

File not fixed

Choose a reason for hiding this comment

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

image File broken

Choose a reason for hiding this comment

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

Remove this file BTW

Choose a reason for hiding this comment

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

remove this file.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from typing import Dict, Anyfrom app.shop import Shopfrom app.car import Carclass Customer: def __init__( self, info: Dict[str, Any], fuel_price: float ) -> None: self.name = info["name"] self.product_cart = info["product_cart"] self.location = info["location"] self.home_location = info["location"] self.money = info["money"] self.car = Car(info.get("car", {}), fuel_price) def calculate_trip_cost( self, fuel_price: float, shop: Shop ) -> int: x1, y1 = self.location x2, y2 = shop.location distance = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 fuel_cost = (distance / 100) * \ self.car.fuel_consumption * fuel_price * 2 products_cost = self.calculate_products_cost(shop) total = round(products_cost + fuel_cost, 2) return total def calculate_products_cost( self, shop: Shop, ) -> float | int: products_cost = sum(amount * shop.products[product] for product, amount in self.product_cart.items() if product in shop.products) return round(products_cost, 2)
Expand Down
44 changes: 41 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
def shop_trip():
# write your code here
pass
import json
from app.customer import Customer
from app.shop import Shop


def shop_trip() -> int:
with open("app/config.json") as file:
data = json.load(file)

fuel_price = data["FUEL_PRICE"]
customers = [Customer(customer, fuel_price)
for customer in data["customers"]]
shops = [Shop(shop) for shop in data["shops"]]

for customer in customers:
print(f"{customer.name} has {customer.money} dollars")

cheapest_shop = None
cheapest_trip_cost = 0

for shop in shops:
cost = customer.calculate_trip_cost(fuel_price, shop)

print(f"{customer.name}'s trip to the {shop.name} costs {cost}")
if not cheapest_shop or cost < cheapest_trip_cost:
cheapest_shop = shop
cheapest_trip_cost = cost

if customer.money < cheapest_trip_cost:
print(f"{customer.name} doesn't have enough money"
f" to make a purchase in any shop")
continue

print(f"{customer.name} rides to {cheapest_shop.name}\n")
cheapest_shop.check_printing(customer)

print(f"{customer.name} rides home")
customer.location = customer.home_location

customer.money -= cheapest_trip_cost
print(f"{customer.name} now has {customer.money} dollars\n")
34 changes: 34 additions & 0 deletions app/shop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import Dict, Any
import datetime


class Shop:
def __init__(
self,
info: Dict[str, Any],
) -> None:
self.name = info["name"]
self.location = info["location"]
self.products = info["products"]

def check_printing(
self,
customer: Any,
) -> None:
current = datetime.datetime.now()
timestamp = f"Date: {current.strftime('%d/%m/%Y %H:%M:%S')}"

print(f"{timestamp.strip()}")
customer.location = self.location
print(f"Thanks, {customer.name}, for your purchase!")
print("You have bought: ")

spent_money = 0
for product, amount in customer.product_cart.items():
if product in self.products:
cost = self.products[product] * amount
spent_money += cost
if cost % 1 == 0:

Choose a reason for hiding this comment

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

You can use cost.is_integer()

Choose a reason for hiding this comment

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

Not fixed

cost = int(cost)
print(f"{amount} {product}s for {cost} dollars")
print(f"Total cost is {spent_money} dollars\nSee you again!\n")
12 changes: 12 additions & 0 deletions car.py

Choose a reason for hiding this comment

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

Why you also need duplicate of file?

Choose a reason for hiding this comment

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

Remove this file.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Dict, Any


class Car:
def __init__(
self,
info: Dict[str, Any],
fuel_price: float,
) -> None:
self.brand = info["brand"]
self.fuel_consumption = info["fuel_consumption"]
self.fuel_price = float(fuel_price)
40 changes: 40 additions & 0 deletions castomer.py

Choose a reason for hiding this comment

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

Why you also need duplicate of file?

Choose a reason for hiding this comment

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

Remove this file.

Choose a reason for hiding this comment

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

Delete this file, please

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from typing import Dict, Any
from app.shop import Shop
from app.car import Car


class Customer:
def __init__(
self,
info: Dict[str, Any],
fuel_price: float
) -> None:
self.name = info["name"]
self.product_cart = info["product_cart"]
self.location = info["location"]
self.home_location = info["location"]
self.money = info["money"]
self.car = Car(info.get("car", {}), fuel_price)

def calculate_trip_cost(
self,
fuel_price: float,
shop: Shop
) -> int:
x1, y1 = self.location
x2, y2 = shop.location
distance = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
fuel_cost = (distance / 100) * \
self.car.fuel_consumption * fuel_price * 2
products_cost = self.calculate_products_cost(shop)
total = round(products_cost + fuel_cost, 2)
return total

def calculate_products_cost(
self,
shop: Shop,
) -> float | int:
products_cost = sum(amount * shop.products[product] for
product, amount in self.product_cart.items()
if product in shop.products)
return round(products_cost, 2)
Empty file added cer.py

Choose a reason for hiding this comment

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

Remove this file

Choose a reason for hiding this comment

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

Remove this file.

Choose a reason for hiding this comment

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

Delete this file, pleaase

Empty file.
Loading