def shopSmart(orderList, fruitShops):
    """
        orderList: List of (fruit, numPound) tuples
        fruitShops: List of FruitShops
    """
    "*** YOUR CODE HERE ***"
    minPrice = float('inf')
    for fruitShop in fruitShops:
        totalPrice = fruitShop.getPriceOfOrder(orderList)
        if totalPrice < minPrice:
            minPrice = totalPrice
            bestFruitShop = fruitShop
    return bestFruitShop


if __name__ == '__main__':
    "This code runs when you invoke the script from the command line"
    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, ", the best shop is", shopSmart(
        orders, shops).getName()
    orders = [('apples', 3.0)]
    print "For orders: ", orders, ", the best shop is", shopSmart(
        orders, shops).getName()
# shopTest.py
# -----------
# Licensing Information: Please do not distribute or publish solutions to this
# project. You are free to use and extend these projects for educational
# purposes. The Pacman AI projects were developed at UC Berkeley, primarily by
# John DeNero ([email protected]) and Dan Klein ([email protected]).
# For more info, see http://inst.eecs.berkeley.edu/~cs188/sp09/pacman.html

import shop

shopName = 'the Berkeley Bowl'
fruitPrices = {'apples': 1.00, 'oranges': 1.50, 'pears': 1.75}
berkeleyShop = shop.FruitShop(shopName, fruitPrices)
applePrice = berkeleyShop.getCostPerPound('apples')
orders1 = [('apples', 1.0), ('oranges', 3.0)]
tcost = berkeleyShop.getPriceOfOrder(orders1)
print applePrice
print('Apples cost $%.2f at %s.' % (applePrice, shopName))
print('Total cost $%.2f at %s.' % (tcost, shopName))

otherName = 'the Stanford Mall'
otherFruitPrices = {'kiwis': 6.00, 'apples': 4.50, 'peaches': 8.75}
otherFruitShop = shop.FruitShop(otherName, otherFruitPrices)
otherPrice = otherFruitShop.getCostPerPound('apples')
print otherPrice
print('Apples cost $%.2f at %s.' % (otherPrice, otherName))
print("My, that's expensive!")
Esempio n. 3
0
import shop

aldiName = 'Aldi'
aldiPrices = {'apples': 1.00, 'oranges': 1.50, 'pears': 1.75}
aldiShop = shop.FruitShop(aldiName, aldiPrices)
aldiApples = berkeleyShop.getCostPerPound('apples')
print(aldiApples)
print('Apples cost €%.2f at %s.' % (aldiApples, aldiName))

albertName = 'Albert Heijn'
albertPrices = {'kiwis': 6.00, 'apples': 4.50, 'peaches': 8.75}
albertShop = shop.FruitShop(albertName, albertPrices)
albertApples = albertShop.getCostPerPound('apples')
print(albertApples)
print('Apples cost €%.2f at %s.' % (albertApples, albertName))
Esempio n. 4
0
import shop

shopName = 'the Butler Bowl'
fruitPrices = {'apples': 1.00, 'oranges': 1.50, 'pears': 1.75}
butlerShop = shop.FruitShop(shopName, fruitPrices)
applePrice = butlerShop.getCostPerPound('apples')
print(applePrice)
print('Apples cost $%.2f at %s.' % (applePrice, shopName))

otherName = 'the Atherton Mall'
otherFruitPrices = {'kiwis': 6.00, 'apples': 4.50, 'peaches': 8.75}
otherFruitShop = shop.FruitShop(otherName, otherFruitPrices)
otherPrice = otherFruitShop.getCostPerPound('apples')
print(otherPrice)
print('Apples cost $%.2f at %s.' % (otherPrice, otherName))
print("My, that's expensive!")
Esempio n. 5
0
For orders:  [('apples', 1.0), ('oranges', 3.0)] best shop is shop1
For orders:  [('apples', 3.0)] best shop is shop2
"""

import shop


def shopSmart(orderList, fruitShops):
    """
        orderList: List of (fruit, numPound) tuples
        fruitShops: List of FruitShops
    """
    costList = []
    for shop in fruitShops:
        eachShopCost = (shop.getPriceOfOrder(orderList))
        costList.append(eachShopCost)
    return fruitShops[costList.index(min(costList))]


fruits1 = {'apples': 2.0, 'oranges': 1.0}
fruits2 = {'apples': 1.0, 'oranges': 5.0}
shop1 = shop.FruitShop('shop1', fruits1)
shop2 = shop.FruitShop('shop2', fruits2)
shops = [shop1, shop2]
orders1 = [('apples', 1.0), ('oranges', 3.0)]
orders2 = [('apples', 3.0)]
print("For order", orders1, "the best shop is",
      shopSmart(orders1, shops).getName())
print("For order", orders2, "the best shop is",
      shopSmart(orders2, shops).getName())
Esempio n. 6
0
import shop

shopName = 'the Berkeley Bowl'
fruitPrices = {'apples': 1.00, 'oranges': 1.50, 'pears': 1.75}
berkeleyShop = shop.FruitShop(shopName, fruitPrices)  #create an object
applePrice = berkeleyShop.getCostPerPound('apples')
#print applePrice
#print('Apples cost $%.2f at %s.' % (applePrice, shopName))

otherName = 'the Stanford Mall'
otherFruitPrices = {'kiwis': 6.00, 'apples': 4.50, 'peaches': 8.75}
otherFruitShop = shop.FruitShop(otherName, otherFruitPrices)
otherPrice = otherFruitShop.getCostPerPound('apples')
#print otherPrice
#print('Apples cost $%.2f at %s.' % (otherPrice, otherName))
#print("My, that's expensive!")

print berkeleyShop.name
print berkeleyShop.fruitPrices