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
Describe with an example how corroded structures can lead to environment pollution? ​
raketka [301]
According to EonCoat, corrosion is the process of decay on a material caused by a chemical reaction with its environment. Corrosion of metal occurs when an exposed surface comes in contact with a gas or liquid, and the process is accelerated by exposure to warm temperature, acids, and salts.” (1)
Although the word ‘corrosion’ is used to describe the decay of metals, all natural and man-made materials are subject to decay, and the level of pollutants in the air can speed up this process.
5 0
3 years ago
List five areas that increased energy prices impact.
Effectus [21]

Answer:

Supply, demand, global markets, imports and exports, and government Regulation.

Explanation:

7 0
3 years ago
How buy airpods in my phone​
Levart [38]

U mean how to connect them to your phone?

4 0
2 years ago
Read 2 more answers
LC3 Programming ProblemUse .BLKW to set up an array of 10 values, starting at memory location x4000, as in lab 4.Now programmati
irga5000 [103]

Answer:

Check the explanation

Explanation:

Code

.ORIG x4000

;load index

LD R1, IND

;increment R1

ADD R1, R1, #1

;store it in ind

ST R1, IND

;Loop to fill the remaining array

TEST LD R1, IND

;load 10

LD R2, NUM

;find tw0\'s complement

NOT R2, R2

ADD R2, R2, #1

;(IND-NUM)

ADD R1, R1, R2

;check (IND-NUM)>=0

BRzp GETELEM

;Get array base

LEA R0, ARRAY

;load index

LD R1, IND

;increment index

ADD R0, R0, R1

;store value in array

STR R1, R0,#0

;increment part

INCR

;Increment index

ADD R1, R1, #1

;store it in index

ST R1, IND

;go to test

BR TEST

;get the 6 in R2

;load base address

GETELEM LEA R0, ARRAY

;Set R1=0

AND R1, R1,#0

;Add R1 with 6

ADD R1, R1, #6

;Get the address

ADD R0, R0, R1

;Load the 6th element into R2

LDR R2, R0,#0

;Display array contents

PRINT

;set R1 = 0

AND R1, R1, #0

;Loop

;Get index

TOP ST R1, IND

;Load num

LD R3,NUM

;Find 2\'s complement

NOT R3, R3

ADD R3, R3,#1

;Find (IND-NUM)

ADD R1, R1,R3

;repeat until (IND-NUM)>=0

BRzp DONE

;load array address

LEA R0, ARRAY

;load index

LD R1, IND

;find address

ADD R3, R0, R1

;load value

LDR R1, R3,#0

;load 0x0030

LD R3, HEX

;convert value to hexadecimal

ADD R0, R1, R3

;display number

OUT

;GEt index

LD R1, IND

;increment index

ADD R1, R1, #1

;go to top

BR TOP

;stop

DONE HALT

;declaring variables

;set limit

NUM .FILL 10

;create array

ARRAY .BLKW 10 #0

;variable for index

IND .FILL 0

;hexadecimal value

HEX .FILL x0030

;stop

.END

7 0
3 years ago
Which best explains Susan B Anthony purpose in her speech “Women’s rights to the suffrage”
Furkat [3]

Answer:

She wrote and delivered a speech in 1873, which came to be known as the “Women's Rights to the Suffrage” speech. In her address, she lets the audience know of her “crime” of voting. She reminds the listener that the Constitution of the United States says “we the people” and does not exclude women as people

6 0
3 years ago
Read 2 more answers
Other questions:
  • A hollow steel tube with an inside diameter of 100 mm must carry a tensile load of 400 kN. Determine the outside diameter of the
    12·2 answers
  • A controller on an electronic arcade game consists of a variable resistor connected across the plates of a 0.227 μF capacitor. T
    6·1 answer
  • At the inlet to the combustor of a supersonic combustion ramjet (or scramjet), the flow Mach number is supersonic. For a fuel-ai
    12·1 answer
  • Under the normal sign convention, the distributed load on a beam is equal to the:_______A. The rate of change of the bending mom
    13·1 answer
  • The Bureau of Labor and Statistics predicted that the field of biomedical engineering would increase by 62 percent over the comi
    5·1 answer
  • A(n) ____ is an exact representation of an object projected onto a plane from a specific position.
    14·1 answer
  • Which option identifies the step of the implementation phase represented in the following scenario?
    9·2 answers
  • Guyss I seriously and urgently need help what are the steps to build a headgear ??​
    5·2 answers
  • "Transformer is used to change the voltage".
    5·1 answer
  • On what kind of sectional drawing would you find the maximum length of a building?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!