Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python list exercize
#1
Hello I'm in high school(I guess, I Don't really know to what it correspond since I'm french) and I've got this excercize which I can't get through. Here is the translated version :

Quote:Exercise 3.2
A burglar breaks into a house. He is only able to carry a limited mass: he will therefore have to choose between different valuables, in order to collect the biggest loot possible.

1. Write an algorithm that gives an optimal choice for the thief.

2. Program in Python language a fill function whose prototype is as follows: fill (list: list, mass: int)
• list - list of items (price, mass)
• mass - maximum mass
We have a list of objects of masses m = [9, 10, 12, 14, 11, 5, 7, 5, 6, 2] as well as their associated values v = [10, 8, 7, 7, 5, 4, 3 , 2, 2, 1].

3. Test the program for a maximum mass of 22 kg. Conclude.


So, my biggest problem here is the task about taking the biggest loot possible, 'cause it means that you have to associate different valuables in order to make the biggest loot possible whithout exceeding the threshold. And I Don't know how to do this. That's why I'm asking if you could help me if it's not too much of a bother.
Thanks in advance !
buran wrote May-23-2020, 07:58 PM:
removed green font color for easier reading.
Quote
#2
Here is a hit:

"associate different valuables"
list = [(price0, mass0), (price1, mass1), (price2, mass2)]

print(list[0][0], list[2][1], list[3][1])

Quote
#3
One approach - find the value per kg of each item, then select the items with the highest value per kg keeping under the 22kg limit total.
Quote
#4
Okay thanks, I will try !
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)