Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

When was the last time you made a prank call?

Answered: 1 week ago

Question

LO23.2 Discuss the extent and sources of income inequality.

Answered: 1 week ago