Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Python list exercize ESTOUR Unladen Swallow Posts: 2 Threads: 1 Joined: May 2020 Reputation: 0 Likes received: 0 #1 May-23-2020, 04:50 PM (This post was last modified: May-23-2020, 07:58 PM by buran. Edited 1 time in total.) 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. michael1789 Minister of Silly Walks Posts: 315 Threads: 28 Joined: May 2019 Reputation: 28 Likes received: 37 #2 May-23-2020, 06:37 PM Here is a hit: "associate different valuables" ```list = [(price0, mass0), (price1, mass1), (price2, mass2)] print(list[0][0], list[2][1], list[3][1]) ``` jefsummers Verb Conjugator Posts: 540 Threads: 1 Joined: May 2019 Reputation: 50 Likes received: 73 #3 May-23-2020, 08:16 PM 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. ESTOUR Unladen Swallow Posts: 2 Threads: 1 Joined: May 2020 Reputation: 0 Likes received: 0 #4 May-23-2020, 11:10 PM Okay thanks, I will try ! « Next Oldest | Next Newest »

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)