please code 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 rounded to 1 decimal place. Your function should raise an exception with the message exactly as shown: a weight is less than 0 or greater than 100 (message: "A weight is less than 0 or greater than 100") the weights do not add to 100 (message: "Weights do not add to 100") the number of weights and grades are not equal (message: "The number of weight and grades are not equal") a grade is below 0 (grades above 100 would be considered extra credit and are acceptable) (message: "A grade is below 0") Do not print the exception just 'raise' it. 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 with the useful message for the user as defined above. Hint: The first 3 test cases should raise an exception! Example: weighted_avg(grades4, weights4) 85.0

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please code 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 rounded to 1 decimal place.

Your function should raise an exception with the message exactly as shown:

  • a weight is less than 0 or greater than 100 (message: "A weight is less than 0 or greater than 100")
  • the weights do not add to 100 (message: "Weights do not add to 100")
  • the number of weights and grades are not equal (message: "The number of weight and grades are not equal")
  • a grade is below 0 (grades above 100 would be considered extra credit and are acceptable) (message: "A grade is below 0")

Do not print the exception just 'raise' it.

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 with the useful message for the user as defined above.

Hint: The first 3 test cases should raise an exception!

Example:

weighted_avg(grades4, weights4)

85.0

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Header Files
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education