From d6d918976e8185064b5b569dd26691879cdec705 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 15 Jan 2024 20:25:37 +0000 Subject: [PATCH] add greatest value with iphone --- chapter11/knapsack.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/chapter11/knapsack.py b/chapter11/knapsack.py index 6c01593..8e7b357 100644 --- a/chapter11/knapsack.py +++ b/chapter11/knapsack.py @@ -48,11 +48,26 @@ def format_and_print(table): table[0][0] = None # print tabularised 2D array + logger.info([item.name for item in items]) logger.info(tabulate(table, tablefmt="pretty")) +# Where items = Guitar + Stereo + Laptop items = [Item("Guitar", 1500, 1), Item("Stereo", 3000, 4), Item("Laptop", 2000, 3)] W = 4 greatest_value = dynamic(items, len(items)) -print(greatest_value) +print(f"Greatest value: {greatest_value}") + + +# Where items = Guitar + Stereo + Laptop + Iphone +items = [ + Item("Guitar", 1500, 1), + Item("Stereo", 3000, 4), + Item("Laptop", 2000, 3), + Item("Iphone", 2000, 1), +] +W = 4 +greatest_value_with_iphone = dynamic(items, len(items)) + +print(f"Greatest value: {greatest_value_with_iphone}")