def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" low = 1000000.0 for shop in fruitShops: price = shop.getPriceOfOrder(orderList) if price < low: low = price lowShopName = shop.getName() return "<FruitShop: " + lowShopName + ">"
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" low = 1000000.0 for shop in fruitShops: price = shop.getPriceOfOrder(orderList) if price<low: low = price lowShopName = shop.getName() return "<FruitShop: "+lowShopName+">"
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ lowestPrice = 9999 bestShop = None for shop in fruitShops: cost = shop.getPriceOfOrder(orderList) print("shop: " + shop.getName() + " cost: " + str(cost)) if cost < lowestPrice: print("new lowest price: " + str(cost)) lowestPrice = cost bestShop = shop return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" priceOfOrder = []; nameOfShop = []; cheaptestShop = 0; for shop in fruitShops: priceOfOrder.append(shop.getPriceOfOrder(orderList)) nameOfShop.append(shop.getName()) for i in range(1,len(priceOfOrder)): if priceOfOrder[cheaptestShop] > priceOfOrder[i]: cheaptestShop = i return "<FruitShop: " + nameOfShop[cheaptestShop] + ">"
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ fruit_shop = None shop_cost = 999999999 for shop in fruitShops : cost = 0 s_name = shop.getName() """ignore the exception of non-existence""" cost = shop.getPriceOfOrder(orderList) if cost <= shop_cost : fruit_shop = shop shop_cost = cost return fruit_shop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ leastPrice = float("inf") for shops in fruitShops: price = shops.getPriceOfOrder(orderList) shop = shops print "***\tThe price of " + shop.getName() + " is " + str(price) if price < leastPrice: leastPrice = price cheapestShop = shop return cheapestShop
def getFruitCostPerPoundOnRoute(self, fruit, route): """ fruit: Fruit string route: List of shop names Returns the best cost per pound of 'fruit' at any of the shops along the route. If none of the shops carry 'fruit', returns None """ routeShops = [shop for shop in self.shops if shop.getName() in route] costs = [] for shop in routeShops: cost = shop.getCostPerPound(fruit) if cost is not None: costs.append(cost) if not costs: # None of the shops carry this fruit return None return min(costs)
def getFruitCostPerPoundOnRoute(self, fruit, route): """ fruit: Fruit string route: List of shop names Returns the best cost per pound of 'fruit' at any of the shops along the route. If none of the shops carry 'fruit', returns None """ routeShops = [ shop for shop in self.shops if shop.getName() in route ] costs = [] for shop in routeShops: cost = shop.getCostPerPound(fruit) if cost is not None: costs.append(cost) if not costs: # None of the shops carry this fruit return None return min(costs)
def shopAroundTown(orderList, fruitTown, gasCost): """ orderList: List of (fruit, numPound) tuples fruitTown: A Town object gasCost: A number representing the cost of going one mile Returns a list of shops in the order that is the optimal route to take when buying the fruit in the orderList """ possibleRoutes = [] subsets = getAllSubsets(fruitTown.getShops()) for subset in subsets: names = [ shop.getName() for shop in subset ] if fruitTown.allFruitsCarriedAtShops(orderList, names): possibleRoutes += getAllPermutations(names) minCost, bestRoute = None, None for route in possibleRoutes: cost = fruitTown.getPriceOfOrderOnRoute(orderList, route, gasCost) if minCost == None or cost < minCost: minCost, bestRoute = cost, route return bestRoute
def shopAroundTown(orderList, fruitTown, gasCost): """ orderList: List of (fruit, numPound) tuples fruitTown: A Town object gasCost: A number representing the cost of going one mile Returns a list of shops in the order that is the optimal route to take when buying the fruit in the orderList """ possibleRoutes = [] subsets = getAllSubsets(fruitTown.getShops()) for subset in subsets: names = [shop.getName() for shop in subset] if fruitTown.allFruitsCarriedAtShops(orderList, names): possibleRoutes += getAllPermutations(subset) minCost, bestRoute = None, None for route in possibleRoutes: cost = fruitTown.getPriceOfOrderOnRoute(orderList, route, gasCost) if minCost == None or cost < minCost: minCost, bestRoute = cost, route return bestRoute