Question: NEED HELP WITH THIS IN PYTHON #Write a function called weighted_avg that takes a list of grades and a corresponding list of weights and returns

NEED HELP WITH THIS IN PYTHON

#Write a function called weighted_avg that takes a list of grades and a corresponding list of weights and returns the weighted average of the grades. Your function should raise an exception if:

#a weight is less than 0 or greater than 100 #the weights do not add to 100 #the number of weights and grades are not equal #a grade is below 0 (grades above 100 would be considered extra credit and are acceptable) #Run your function on grades1 with weights1 and grades2 with weights2 and grades3 with weights3 and grades4 with weights4, defined below. Catch the errors generated in each case as an exception and print a useful message for the user.

#Hint: The first 3 test cases should return an exception!

#Example: #weighted_avg(grades4, weights4) #85.0 grades1 = [88,99,100,70] weights1 = [30, 30, 30, 5]

grades2 = [78, 75, 80, 99] weights2 = [110, 10, -20, 0]

grades3 = [84, 80, 67, 97] weights3 = [50, 25, 25]

grades4 = [100, 80, 90, 75] weights4 = [20, 25, 25, 30]

### [Please put your name here]

def weighted_avg(n): # YOUR CODE HERE raise NotImplementedError()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!