Question: 3. Write a function square_evens(values) that takes a list of integers called values, and that modifies the list so that all of its even elements

 3. Write a function square_evens(values) that takes a list of integers

3. Write a function square_evens(values) that takes a list of integers called values, and that modifies the list so that all of its even elements are replaced with their squares, but all of its odd elements are left unchanged. This function should not return a value. Rather, it should should use a loop to modify thee 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: >vals1- [1, 2, 3, 4, 5, 6]) square_evens(vals1) >>>vals1 [1, 4, 3, 16, 5, 36] vals2 [7, 3, 10, 8]) square_evens(vals2) >vals2 07, 3, 100, 64]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!