1.)Given a set, weights , and an integer desired_weight , remove the element of
ID: 3860609 • Letter: 1
Question
1.)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.
2.) Given that v has been defined, and that s that refers to a set, write a statement that attempts to remove the value associated with v from set s, but will do nothing if it is not in s.
code lab help!!! python 3.0
Explanation / Answer
NOTE: I have completed the code for your assignment. Please check and let me know if you face any issues. I will revert back within 24 hours.
Code:
http://pasted.co/c855fc5e
Code execution screenshot:
https://pasteboard.co/GCEJWPt.png
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.