My Programming Lab PYTHON help please Given a set weights an
My Programming Lab (PYTHON) help please...
Given a set, weights, and an integer desired_weight, remove the element of the set that is closest to, but not 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, 19, 6, 22, 7) and actual_weight would be 14. Assume there is at least one value in the set that is less than desired_weight.
Solution
def labPython():
weights = {12, 19, 6, 14, 22, 7}
desired_weight = 18
max_weight_lt_desired_weight = 0
actual_weight = 0
for w in weights:
if w > max_weight_lt_desired_weight and w < desired_weight :
actual_weight = w
weights.remove(actual_weight)
print(weights)
print(actual_weight)
labPython()
