Question: Python Use loop Write a function negate_odds (values) that takes a list of integers called values, and that modifies the list so that all of
Write a function negate_odds (values) that takes a list of integers called values, and that modifies the list so that all of its odd- valued elements are replaced with their negated values, but all of its even-valued elements are left unchanged This function should not return a value Rather, it should should use a loop to modify the internals of the original list as needed For example, to modify element i of the list values, you should perform an assignment that looks like this values[i] = expression where expression is replaced with an appropriate expression for the new value of values [i. For reasons that we will discuss in lecture this week, any changes that the function makes to the internals of the list will still be there after the function returns. For example >>>valsi-[1, 2, 3, 4, 5, 6] >>>negate odds (vals1) >>vals1 >>> vals2 = [7, -3, 10, 8, -1] >>>negate odds (vals2) >>>vals2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
