Skip to content

Commit

Permalink
Solution-four-py-shop-trip
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadiia-developer committed Oct 12, 2023
1 parent 2618c85 commit e9b8c25
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 34 deletions.
File renamed without changes.
Empty file removed app/car/__init__.py
Empty file.
32 changes: 28 additions & 4 deletions app/customer/customer.py → app/customer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
import math
from typing import Dict, Any, List

from app.car.car import Car
from app.shop.shop import Shop
from app.car import Car


class Customer:
Expand All @@ -14,7 +14,7 @@ def __init__(self, data: Dict[str, Any]) -> None:
self.money = data["money"]
self.car = Car(data["car"])

def calculate_trip_cost(self, shop: Shop) -> float:
def calculate_trip_cost(self, shop: "Shop") -> float:
distance_to_shop = self.calculate_distance(shop.location)
fuel_consumption_per_km = self.car.fuel_consumption / 100
fuel_cost_to_shop = (
Expand All @@ -32,7 +32,7 @@ def calculate_trip_cost(self, shop: Shop) -> float:
def has_enough_money(self, trip_cost: float) -> bool:
return self.money >= trip_cost

def travel_to_shop(self, shop: Shop) -> None:
def travel_to_shop(self, shop: "Shop") -> None:
self.location = shop.location
print(f"{self.name} rides to {shop.name}\n")

Expand All @@ -46,3 +46,27 @@ def calculate_distance(self, shop_location: List[int]) -> float:
y_location = self.location[1] - shop_location[1]
distance = math.sqrt(x_location**2 + y_location**2)
return distance


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

def sell_products(self, customer: Customer) -> None:
print(
f"\nDate: "
f"{datetime.datetime.now().strftime('%d/%m/%Y %H:%M:%S')}\n"
)
print(f"Thanks, {customer.name}, for your purchase!\n")
total_cost = 0
for product, quantity in customer.product_cart.items():
product_cost = quantity * self.products[product]
print(
f"You have bought: {quantity} {product}s "
f"for {product_cost} dollars\n"
)
total_cost += product_cost
print(f"Total cost is {total_cost} dollars\n")
print("See you again!\n")
Empty file removed app/customer/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from app.customer.customer import Customer
from app.shop.shop import Shop
from app.customer import Customer
from app.customer import Shop


def shop_trip() -> None:
Expand Down
Empty file removed app/shop/__init__.py
Empty file.
28 changes: 0 additions & 28 deletions app/shop/shop.py

This file was deleted.

0 comments on commit e9b8c25

Please sign in to comment.