Question: Q# 2 : ( 8 points ) . Use programming concepts only from the chapter Decision structure, Repetition structure, Function, Files and Exceptions, Lists /
Q#: points Use programming concepts only from the chapter Decision structure, Repetition structure, Function, Files and Exceptions, ListsTuples and Strings.
Define a function calculatestats 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, evencountSave the calculatestats function in a separate file named statscalculator using the magic function.
Write the main program that:
Randomly generte intger numbers between and both inclusive create a list of these integers and named it numbers.Imports the calculatestats function from statscalculatorCalls the calculatestats function with the numbers list and captures the returned values.Stores the returned values sum average, evencount in a new list called statslist and display the content of the list one by one.
Sample:
sum:
average
count
Performs the following operations on statslist and display all:
Inserts the numbers and at the beginning of the list.Reverses the order of statslist.Finds the index of the original sum value in the list and replaces it with the value Sorts the list Deletes the last element from statslist.
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
