Answer to Question #318202 in Python for hatipo

Question #318202

Problem 2: Fill in the function shopSmart(orders,shops) in shopSmart.py, which takes an orderList (like the kind passed in to FruitShop.getPriceOfOrder) and a list of FruitShop and returns the FruitShop where your order costs the least amount in total. Don't change the file name or variable names, please. Note that we will provide the shop.py implementation as a "support" file, so you don't need to submit yours. Test Case: We will check that, with the following variable definitions: orders1 = [('apples',1.0), ('oranges',3.0)] orders2 = [('apples',3.0)] dir1 = {'apples': 2.0, 'oranges':1.0} shop1 = shop.FruitShop('shop1',dir1) dir2 = {'apples': 1.0, 'oranges': 5.0} shop2 = shop.FruitShop('shop2',dir2) shops = [shop1, shop2] The following are true: shopSmart.shopSmart(orders1, shops).getName() == 'shop1' and shopSmart.shopSmart(orders2, shops).getName() == 'shop2'


1
Expert's answer
2022-03-26T02:38:58-0400
def shopSmart(orders,shops):
    dic = {}
    for i, j in enumerate(orders):
        dic[j] = shops[i]
    return min(dic)
    

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS