Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python w rite list functions that carry out the following tasks for a list of integers ( copy the ONE_TEN to a separate List

Using Python write list functions that carry out the following tasks for a list of integers (copy the ONE_TEN to a separate List so you can reuse them). For each function, provide a test program. Use the starting code below:

def main() :

# Define constant variables (list hardcoded).

ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

print("The original data for all functions is: ", ONE_TEN)

# Demonstrate swapping the first and last element.

data = list(ONE_TEN)

swapFirstLast(data)

print("After swapping first and last: ", data)

A) Swap the first and last elements in the list. (Call is in the starting code above)
B) Replace all even elements with a zero
C) Return the second-largest element in the list
D) Return true if the list is currently sorted in increasing order.

Expected output:

The original data for all functions is: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

After swapping first and last: [10, 2, 3, 4, 5, 6, 7, 8, 9, 1]

After replacing even elements: [1, 0, 3, 0, 5, 0, 7, 0, 9, 0]

The second largest value is: 9

The list is in increasing order: True

screenshot code with comments

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_2

Step: 3

blur-text-image_3

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

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions