Python please!!! Please use all variable names in response and this shoud have n
ID: 3705715 • Letter: P
Question
Python please!!! Please use all variable names in response and this shoud have no print statements
Given a set, weights, and an integer desired_weight, remove the element of the set that is closest to desired_weight (the closest element can be less than, equal to OR GREATER THAN desired_weight), and associate it with the variable actual_weight. For example, if weights is (12, 19, 6, 14, 22, 7) and desired_weight is 18, then the resulting set would be (12, 6, 14, 22, 7) and actual_weight would be 19. If there is a tie, the element LESS THAN desired_weight is to be chosen. Thus if the set is (2, 4, 6, 8, 10) and desired_weight is 7, the value chosen would be 6, not 8. Assume there is at least one value in the set.
Explanation / Answer
Hi Dear,
Please find my implementation.
Output:
Enter how many weights you want? 6
Enter weight for 1 : 12
Enter weight for 2 : 19
Enter weight for 3 : 6
Enter weight for 4 : 14
Enter weight for 5 : 22
Enter weight for 6 : 7
Given weights set is [12, 19, 6, 14, 22, 7]
Enter the desired weight 18
Resulting set is [12, 6, 14, 22, 7]
Actual weight is: 19
Process finished with exit code 0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.