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]
3 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]3 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
Water from the Earth's surface turns into a gas, or water vapor, when it is warmed and
bagirrra123 [75]

Answer:

Evaporation.

Explanation:

Evaporation is the stage of the Water Cycle where water turns into water vapor. The steps following Evaporation in order include Condensation, Precipitation, and Transpiration.

4 0
3 years ago
Read 2 more answers
4. Water vapor enters a turbine operating at steady state at 1000oF, 220 lbf/in2 , with a volumetric flow rate of 25 ft3/s, and
hodyreva [135]
Yes i is the time of the day you get to frost the moon and back and then you can come over and then go to hang out with me me and then go to hang out
6 0
3 years ago
Troy must keep track of the amount of refrigerant he uses from a 50-pound cylinder to ensure that accurate
IgorLugansk [536]

Answer:

Amount of gas still in cylinder = 28 pound

Explanation:

Given:

Amount of gas in cylinder = 50 pound

Amount of gas used in Ms. Jones system = 13 pound

Amount of gas used in client system = 9 pound

Find:

Amount of gas still in cylinder

Computation:

Amount of gas still in cylinder = Amount of gas in cylinder - Amount of gas used in Ms. Jones system - Amount of gas used in client system

Amount of gas still in cylinder = 50 - 13 - 9

Amount of gas still in cylinder = 28 pound

7 0
3 years ago
(Gas Mileage) Drivers are concerned with the mileage their automobiles get. One driver has kept track of several trips by record
Effectus [21]

Answer:

import java.util.*;

public class Main {

   

   public static void main(String[] args) {

     

       double milesPerGallon = 0;

       int totalMiles = 0;

       int totalGallons = 0;

       double totalMPG = 0;

       

       Scanner input = new Scanner(System.in);

 

       while(true){

           System.out.print("Enter the miles driven: ");

           int miles = input.nextInt();

           if(miles <= 0)

               break;

           else{

               System.out.print("Enter the gallons used: ");

               int gallons = input.nextInt();

               totalMiles += miles;

               totalGallons += gallons;

               milesPerGallon = (double) miles/gallons;

               totalMPG = (double) totalMiles / totalGallons;

               System.out.printf("Miles per gallon for this trip is: %.1f\n", milesPerGallon);

               System.out.printf("Total miles per gallon is: %.1f\n", totalMPG);

           }

       }

   }  

}

Explanation:

Initialize the variables

Create a while loop that iterates until the specified condition is met inside the loop

Inside the loop, ask the user to enter the miles. If the miles is less than or equal to 0, stop the loop. Otherwise, for each trip do the following: Ask the user to enter the gallons. Add the miles and gallons to totalMiles and totalGallons respectively. Calculate the milesPerGallon (divide miles by gallons). Calculate the totalMPG (divide totalMiles by totalGallons). Print the miles per gallon and total miles per gallon.

6 0
3 years ago
When the 2.8-kg bob is given a horizontal speed of 1.5 m/s, it begins to rotate around the horizontal circular path A. The force
Rama09 [41]

Answer:

The speed is the same at 1.5 m/s while

The work done by the force F is 0.4335 J

Explanation:

Here we have angular acceleration α = v²/r

Force = ma = 2.8 × 1.5²/r₁

and ω₁ = v₁/r₁ = ω₂ = v₁/r₂

The distance moved by the force = 600 - 300 = 300 mm = 0.3 m

If the velocity is constant

The speed is 1.5 m/s while the work done is

2.8 × 1.5²1/(effective radius) ×0.3

r₁ = effective radius

2.8*9.81 = 2.8 × 1.5²/r₁

r₁ = 0.229

The work done by the force = 2.8 × 1.5²*1/r₁ *0.3 = 0.4335 J

4 0
3 years ago
Other questions:
  • The statement that is NOT true about the concept of a boundary layer on an object is: a. the Reynolds number is greater than uni
    6·1 answer
  • A steam power plant operates on an ideal Rankine cycle with two stages of reheat and has a net power output of 120 MW. Steam ent
    14·1 answer
  • A thick oak wall (rho = 545 kg/m3 , Cp = 2385 J/kgK, and k = 0.17 W/mK) initially at 25°C is suddenly exposed to combustion prod
    11·1 answer
  • Select the correct answer.<br> Which equation gives you the amount of work performed?
    14·1 answer
  • A light bar AD is suspended from a cable BE and supports a 20-kg block at C. The ends A and D of the bar are in contact with fri
    13·1 answer
  • Can someone teach me how to find all valid minterms of any given truth table?
    11·1 answer
  • What is the heart of a set of construction drawing?
    10·1 answer
  • Water flows through a converging pipe at a mass flow rate of 25 kg/s. If the inside diameter of the pipes sections are 7.0 cm an
    13·1 answer
  • Which best explains Susan B Anthony purpose in her speech “Women’s rights to the suffrage”
    9·2 answers
  • Whats the difference between GeForce GTX 1060 and Geforce GTX 3060? Is there any big changes to FPS and other settings?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!