You are looking to rob a jewelry store. You have been staking it out for a couple of weeks now and have learned the weights and values of every item in the store. You are looking to get the biggest score you possibly can but you are only one person and your backpack can only fit so much. Write a function called get_best_backpack(items: List[Item], max_capacity: int) -> "List[Item]" that accepts a list of Items as well as the maximum capacity that your backpack can hold and returns a list containing the most valuable items you can take that still fit in your backpack

Respuesta :

Answer:

The writting code will be for =>

(1). item.py.

(2). code.py.

(3). test.py.

Explanation:

NB: kindly download the doc. attachment below for the code for (2). code.py and (3). test.py.

So, we will be writting a working code for the three files and they are; item.py, code.py and test.py.

(1). Item.py.

class Item(object):

def __init__(self, name: str, weight: int, value: int) -> None:

self.name = name

self.weight = weight

self.value = value

def __lt__(self, other: "Item"):

if self.value == other.value:

if self.weight == other.weight:

return self.name < other.name

else:

return self.weight < other.weight

else:

return self.value < other.value

def __eq__(self, other: "Item") -> bool:

if isinstance(other, Item):

return (self.name == other.name and

self.value == other.value and

self.weight == other.weight)

else:

return False

def __ne__(self, other: "Item") -> bool:

return not (self == other)

def __str__(self) -> str:

return f'A {self.name} worth {self.value} that weighs {self.weight}'

Ver imagen codedmog101
RELAXING NOICE
Relax