Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions