From 58c397501a1363a7d1e4d447b30ba0544f4a81d8 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Tue, 25 Jun 2024 07:47:52 +0000 Subject: [PATCH] finish tutorial tasks --- .gitignore | 5 ++++- tutorial/addition.py | 4 +--- tutorial/buyLotsOfFruit.py | 4 +++- tutorial/shopSmart.py | 6 +++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 819c4ca..0a4146c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ multiagent1/ -__pycache__/ \ No newline at end of file +__pycache__/ +/.vscode +/.devcontainer +/.github \ No newline at end of file diff --git a/tutorial/addition.py b/tutorial/addition.py index 3c76728..1dc4a69 100644 --- a/tutorial/addition.py +++ b/tutorial/addition.py @@ -18,6 +18,4 @@ Run python autograder.py def add(a, b): - "Return the sum of a and b" - "*** YOUR CODE HERE ***" - return 0 + return a+b \ No newline at end of file diff --git a/tutorial/buyLotsOfFruit.py b/tutorial/buyLotsOfFruit.py index a02448d..54ef758 100644 --- a/tutorial/buyLotsOfFruit.py +++ b/tutorial/buyLotsOfFruit.py @@ -35,7 +35,9 @@ def buyLotsOfFruit(orderList): Returns cost of order """ totalCost = 0.0 - "*** YOUR CODE HERE ***" + for item in orderList: + fruit, numPounds = item + totalCost += fruitPrices[fruit] * numPounds return totalCost diff --git a/tutorial/shopSmart.py b/tutorial/shopSmart.py index fbbd3ca..21d5f69 100644 --- a/tutorial/shopSmart.py +++ b/tutorial/shopSmart.py @@ -30,7 +30,11 @@ def shopSmart(orderList, fruitShops): fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" - return None + best_shop=fruitShops[0] + for show in fruitShops: + if best_shop.getPriceOfOrder(orderList)>show.getPriceOfOrder(orderList): + best_shop=show + return best_shop if __name__ == '__main__':