File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -85,11 +85,14 @@ def knapsack_space_optimized(
8585 item_weight = weights [item_index ]
8686 item_value = values [item_index ]
8787 if not isinstance (item_weight , int ):
88- raise TypeError (f"Weight at index { item_index } must be an integer." )
88+ msg = f"Weight at index { item_index } must be an integer."
89+ raise TypeError (msg )
8990 if item_weight < 0 :
90- raise ValueError (f"Weight at index { item_index } cannot be negative." )
91+ msg = f"Weight at index { item_index } cannot be negative."
92+ raise ValueError (msg )
9193 if not isinstance (item_value , int ):
92- raise TypeError (f"Value at index { item_index } must be an integer." )
94+ msg = f"Value at index { item_index } must be an integer."
95+ raise TypeError (msg )
9396
9497 dp = [0 ] * (capacity + 1 )
9598 for item_index in range (num_items ):
You can’t perform that action at this time.
0 commit comments