From 85481bd3d337a3c17b5a7d7c9434f043672a0d16 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 15 Jan 2024 18:28:16 +0000 Subject: [PATCH] no need to pass W, it's global. --- chapter11/knapsack.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapter11/knapsack.py b/chapter11/knapsack.py index 45f4c6a..264b496 100644 --- a/chapter11/knapsack.py +++ b/chapter11/knapsack.py @@ -18,7 +18,7 @@ class Item: weight: int -def dynamic(W, items, n): +def dynamic(items, n): # create table and zero fill it (required for calculations) table = [[0 for _ in range(W + 1)] for _ in range(n + 1)] @@ -53,6 +53,6 @@ def format_and_print(table): items = [Item("Guitar", 1500, 1), Item("Stereo", 3000, 4), Item("Laptop", 2000, 3)] W = 4 -greatest_value = dynamic(W, items, len(items)) +greatest_value = dynamic(items, len(items)) print(greatest_value)