Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Error Finder Function Name: error_finder Parameters: numList (list), indexList (list) Returns: (average, errorDict) (tuple) Description: Write a function that takes in a list of numbers
Error Finder Function Name: error_finder Parameters: numList (list), indexList (list) Returns: (average, errorDict) (tuple) Description: Write a function that takes in a list of numbers and a list of indices. Note that in- dexList may not only contain valid indices. The function should keep track of the number and type of errors that occur. Specifically, it should account for IndexError and TypeError. It should return the average of all the numbers at valid indices and a dictionary containing the number and type of errors together in a tuple. errorDict should be formatted as follows: {"IndexError": 0, "TypeError":0} If none of the indices in the indexList are valid, the function should return 0 as the average. >>> numList = [4,5,1,7,2,3,6] >>> indexList = [0, "4", (1,), 18, "", 3, 5.0, 7.0, {}, 20] >>print(error_finder(numList, indexList)) (5.5, {"IndexError': 2, "TypeError': 6}) >>numList = [1, 0, 18, 22, 3, -1, 5, 4, 9] >> indexList = [(7.), 4.0, {True: False}, 0, [11], "not an index", 12, 2.5] >>print(error_finder(numList, indexList)) (1.0, {"IndexError': 1, "TypeError': 6})
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started