a guest Jul 22nd, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- ebeebay is a online marketplace. A Seller in ebeebay wants to sell Q quantity for P price each.
- And there are many interested buyers - 1st buyer want to purchase Q1 quantities at P1 price each.
- and 2nd buyer wants to purchase Q2 qunaities at P2 price each. so on.. where Q = Q1 + Q2 + Q3 + ... + Qn.
- ebeebay is a neutral market place where it tries to find the mid price for both parties and make a best deal.
- SELLER wants to sell 100 (Q) smartphones at 200$ (P) each = 20000$ total selling price
- BUYER1 wants to buy 60 (Q1) smartphones at 220$ (P1) = 13200$ total buying price
- BUYER2 wants to buy 40 (Q2) smartphones at 210$ (P2) = 8400$ total buying price
- caclculate mid price for each deal
- SELLER & BUYER1 deal - 60 smartphones at 210$ (200+220)/2 price each.
- SELLER & BUYER2 deal - 40 smartphones at 205$ (200+210)/2 price each.
- 20800$ will be total selling price for SELLER (deal price)
- 12600$ will be total buying price for BUYER1
- 8200$ will be total buying price for BUYER2
- Now complete below python program which takes 1 seller qty & price and n buyer qty & prices.
- 1. print total selling price
- 2. print each buyers total buying price
- 3. find best buyer who contributed highest buy to the deal.
- class RetailOrder(object):
- def __init__(self, qty, price):
- self.qty = qty
- self.price = qty
- # seller - 1 RetailOrder with qty & price
- # buyers - list of RetailsOrder's with qty & price
- # implement you deal making logic below
- def ebeebay_make_best_deal(seller, buyers)
RAW Paste Data