1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jarptica [38.1K]
4 years ago
8

Description: Write a function that takes in a list of numbers and a list of indices. Note that indexList may not only contain va

lid 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 follow
Engineering
1 answer:
MAVERICK [17]4 years ago
7 0

Answer:

Python code is explained below

Explanation:

average , count, indexerror, typeerror variables are initialised to 0

Then, for loop is used to traverse the indexlist, if type is not right, typeerror is incremented, else if index is not right, indexerror is incremented, otherwise, count is incremented, and the number is added to average.

At last, average variable which contains the sum of numbers is divided by count to get average.

Here is the code:

def error_finder(numList, indexList):

average = 0

count = 0

indexerror = 0

typeerror = 0

 

for i in range(len(indexList)):

if type(indexList[i])==int:

if indexList[i]>=len(numList) or i<0:

indexerror = indexerror + 1

else:

average = average + numList[indexList[i]]

count = count+1

else:

typeerror = typeerror + 1

 

d = {"IndexError": indexerror, "TypeError":typeerror}

 

average = average/count

 

return(average, d)

print(error_finder([4, 5, 1, 7, 2, 3, 6], [0, "4", (1, ), 18, "", 3, 5.0, 7.0, {}, 20]))

You might be interested in
An electrochemical cell is composed of pure nickel and pure iron electrodes immersed in solutions of their divalent ions. If the
xenn [34]

Answer:C  0.12 V

Explanation:

Given

Concentration of Fe^{2+} M_1=0.40 M

Concentration of Ni^{2+} M_2=0.002 M

Standard Potential for Ni and Fe are V_2=-0.25 V  and V_1=-0.44 V

\Delta V=V_2-V_1-\frac{0.0592}{2}\log (\frac{M_1}{M_2})

\Delta V=-0.25-(-0.44)-\frac{0.0592}{2}\log (\frac{0.4}{0.002})

\Delta V=0.12\ V

7 0
3 years ago
Careful planning will save time, __________, and energy while ensuring the production of a high quality product.
Svet_ta [14]
Juicers nb 345676 at that rate it will be amazing
5 0
2 years ago
Short-term memoryA) has a larger storage capacity than long-term memory.B) takes longer to retrieve than long-term memory.C) inv
zaharov [31]

Answer:D

Explanation:

Take longer time to retrieve than long term memory, involves transient modifications in the function of pre existing synapses, such as channel modifications.

6 0
3 years ago
How can we love our country? Not by words but by deeds. - Jose P. Laurel
Vadim26 [7]

Answer:

1. You have the courage to help without expecting a reward.

2. Because actions are more eloquent than words. Actions are far more valuable and counted than  words, and that's how she inspired me.

3. Doing simple things that can make someone grateful and happy  without knowing that someone is inspired and motivated by your good deeds, and also doing some interesting things By.

Explanation:

6 0
3 years ago
What is NOT an example of professional networking?
gogolik [260]

Answer:

funfairs etc

Explanation:

6 0
4 years ago
Other questions:
  • 9 b. A sign (including the post and base) weighs 40 pounds and is
    8·1 answer
  • One-dimensional, steady-state conduction with uniform internal energy generation occurs in a plane wall with a thickness of 50 m
    14·1 answer
  • What are the advantages of using 3D ink jet printing?
    10·1 answer
  • Suppose that the time (in hours) required to repair a machine is an exponentially distributed random variable with parameter ???
    13·1 answer
  • 5) Initially, the pressure and temperature of steam inside a solid capsule is at 100-pound force per square inch absolute (psia)
    6·1 answer
  • Yooo. does anyone have tin foil and tape mask that they can take a picture of and send it ?
    5·1 answer
  • Please help me with this. Picture
    5·1 answer
  • Can somebody help me with that
    13·1 answer
  • Sometimes we need to create heat, such as in circuit breakers and rear window
    5·2 answers
  • It is acceptable to mix used absorbents.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!