Coder Social home page Coder Social logo

py-shop-trip's Introduction

Shop trip

You want to create an application that helps customers to choose the cheapest trip for the products.

There is config.json file that contains:

  • FUEL_PRICE - Price for 1 liter of fuel in dollars.
  • customers - list of dictionaries with information about each customer.
  • shops - list of dictionaries with information about each shop in the city.

You have information about

Customers:

  • name
  • products he wants to buy
  • location
  • money
  • car
    • brand
    • volume of fuel consumption for 100 kilometers.

Shops:

  • name
  • location
  • products that shop provides

Write shop_trip function that doesn't take any argument, where customers calculate how much will cost trip for the products in every shop and pick the cheapest one and ride there if they have enough money. When the customer arrives at the shop his location should equal to shop location. After customer buys products, shop prints purchase receipt using current time. After the shop he arrives home and counts the remaining money.

The cost of the trip consists of three parts: the fuel cost to get to the shop, cost of all products to buy, the fuel cost to get home.

For example, let's say now is 2021/01/04 12:33:41:

 // config.py:

{
    "FUEL_PRICE": 2.4,   
    "customers": [
        {
            "name": "Bob",
            "product_cart": {
                "milk": 4,
                "bread": 2,
                "butter": 5
            },
            "location": [12, -2],
            "money": 55,
            "car": {
                "brand": "Suzuki",
                "fuel_consumption": 9.9
            }
        },
        {
            "name": "Monica",
            "product_cart": {
                "milk": 3,
                "bread": 3,
                "butter": 1
            },
            "location": [11, -2],
            "money": 12,
            "car": {
                "brand": "Audi",
                "fuel_consumption": 7.6
            }
        }
    ],
    "shops": [
        {
            "name": "Outskirts Shop",
            "location": [10, -5],
            "products": {
                "milk": 3,
                "bread": 1,
                "butter": 2.5
            }
        },
        {
            "name": "Shop '24/7'",
            "location": [4, 3],
            "products": {
                "milk": 2,
                "bread": 1.5,
                "butter": 3.2
            }
        },
    ]
}
# main.py:
shop_trip()

# Bob has 55 dollars
# Bob's trip to the Outskirts Shop costs 28.21
# Bob's trip to the Shop '24/7' costs 31.48
# Bob rides to Outskirts Shop
# 
# Date: 2021/01/04 12:33:41
# Thanks, Bob, for you purchase!
# You have bought: 
# 4 milks for 12 dollars
# 2 breads for 2 dollars
# 5 butters for 12.5 dollars
# Total cost is 26.5 dollars
# See you again!
# 
# Bob rides home
# Bob now has 26.79 dollars
#
# Monica has 12 dollars
# Monica's trip to the Outskirts Shop costs 15.65
# Monica's trip to the Shop '24/7' costs 16.84
# Monica doesn't have enough money to make purchase in any shop

You design application architecture by yourself.

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

py-shop-trip's People

Contributors

masterpieceelbow avatar abnormaltype avatar ivanramyk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.