Question: Write a Python function called weighted_avg that takes a list of grades and a corresponding list of weights and returns the weighted average of the
Write a Python 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!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
