Question: 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

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!