Reference no: EM132355023
Question
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.
Note: your code must work for any input (not just these numbers)
a) Your code with comments
b) A screenshot of the execution
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