📄 shopsmart.py
字号:
import shop
def shopSmart(orderList, fruitShops):
"""
orderList: List of (fruit, numPound) tuples
fruitShops: List of FruitShops
"""
minCost, argMin = None, None
for shop in fruitShops:
cost = shop.getPriceOfOrder(orderList)
if minCost == None or cost < minCost:
minCost, argMin = cost, shop
return argMin
if __name__ == '__main__':
orders = [('apples',1.0), ('oranges',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]
print "For orders: ", orders, "best shop is", shopSmart(orders, shops).getName()
orders = [('apples',3.0)]
print "For orders: ", orders, "best shop is", shopSmart(orders, shops).getName()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -