Question: Q# 2 : ( 8 points ) . Use programming concepts only from the chapter Decision structure, Repetition structure, Function, Files and Exceptions, Lists /

Q#2: (8 points). Use programming concepts only from the chapter Decision structure, Repetition structure, Function, Files and Exceptions, Lists/Tuples and Strings.
Define a function calculate_stats that takes a list of integers and calculates:
The sum of all numbers.The average of the numbers.The count of even numbers in the list.The function should return these three values as a tuple in the order: (sum, average, even_count).Save the calculate_stats function in a separate file named stats_calculator using the magic function.
Write the main program that:
Randomly generte 10 intger numbers between 10 and 500(both inclusive), create a list of these integers and named it numbers.Imports the calculate_stats function from stats_calculatorCalls the calculate_stats function with the numbers list and captures the returned values.Stores the returned values (sum, average, even_count) in a new list called stats_list and display the content of the list one by one.
Sample:
sum: 453
average=12.34
count =6
Performs the following operations on stats_list and display all:
Inserts the numbers 100,500, and 800 at the beginning of the list.Reverses the order of stats_list.Finds the index of the original sum value in the list and replaces it with the value 999.9.Sorts the list .Deletes the last element from stats_list.
Note:Consider exceptions to catch and deal with any potential errors that might occur during file operations or the calculation process.Use at least two specific exception handling.

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 Programming Questions!