Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Python
Use loop image text in transcribed
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

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 Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions