Lists Challenges 2
Complete the 9+ challenges, see the started code on Replit Teams.
Follow the instructions to open a file to write to
Follow the instructions to read from a file
Separate using commas
Turn data into an integer list
Call function to perform all tests
Pass the list and the file as parameters
Break out of loop if no more data, or error getting next line
Close the files
Calculate the sum of the data
Calculate the average value of the data
Find the maximum value of the data
Find the minimum value of the data
Find the range of the data
Find the index of the maximum value of the data
Find the index of the minimum value of the data
*extra credit* Find the second largest value of the data
data.txt contents:
5, -3, 3, 25, 33, 4, 3, -6, 0, 12
4, -4, 8, 26, 20, 4, 6, -10, 0, 10, 2
3
-5, -10, -15, -20, -25, -30, -35, -40, -45, -50
results.txt contents:
All Results for: [5, -3, 3, 25, 33, 4, 3, -6, 0, 12]
Sum of all elements: 76
Average value of all elements: 7.6
Max element in list: 33
Min element in list: -6
Range of elements: 39
Max index in list: 4
Min index in list: 7
2nd largest in list: 25
---
All Results for: [4, -4, 8, 26, 20, 4, 6, -10, 0, 10, 2]
Sum of all elements: 66
Average value of all elements: 6.0
Max element in list: 26
Min element in list: -10
Range of elements: 36
Max index in list: 3
Min index in list: 7
2nd largest in list: 20
---
All Results for: [3]
Sum of all elements: 3
Average value of all elements: 3.0
Max element in list: 3
Min element in list: 3
Range of elements: 0
Max index in list: 0
Min index in list: 0
2nd largest in list: No second value
---
All Results for: [-5, -10, -15, -20, -25, -30, -35, -40, -45, -50]
Sum of all elements: -275
Average value of all elements: -27.5
Max element in list: -5
Min element in list: -50
Range of elements: 45
Max index in list: 0
Min index in list: 9
2nd largest in list: -10
---