Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Grade Average with Exceptions ( Python) This assignment is to modify Programming Assignment 4 Grade Average to make it robust. In industry, a robust program

image text in transcribed

Grade Average with Exceptions ( Python)

This assignment is to modify Programming Assignment 4 Grade Average to make it robust. In industry, a robust program is one that the user cannot cause an exception to occur. To do that, the programmer needs to catch all possible exceptions within the program, give an intelligent error message to the user, and allow the user to reenter the data so the program may continue. In the Grade Average program, there are two possible exceptions that can be caused by the user; the user can type in something that is not a number, e.g. 'fred', causing a TypeError, or the user can enter a negative number without entering any numbers to average causing a ZeroDivisionError. You must modify the program to use a loop any place the user enters a number to keep requesting them to enter a number until they enter a number.

You will also add the following function to your program: calculateAverage(sum, count) where sum is the sum to be averaged and count is the count of the numbers in sum. It will return the average which is simply sum/count or it will raise a ValueError if count = 0. In the main logic of the program, you will call calculateAverage to get the average but must catch the ValueError if it is raised.

You will see that by making the program robust, you will more than double the amount of code in the assignment.

Sample execution: Python 3.6.4 Shell File Edit Shell Debug Options Window Help Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license )" for more information. RESTART: P:/Cmpsc131/Programming Assignment Solutions/PA13AverageofNumbersWithExceptions.py Enter a positive number to total or a negative number to calculate average: 10 Enter a positive number to total or a negative number to calculate average: 20 Enter a positive number to total or a negative number to calculate average: up What you entered was not a valid number. Try again. Enter a positive number to total or a negative number to calculate average: 30 Enter a positive number to total or a negative number to calculate average: 40 Enter a positive number to total or a negative number to calculate average: -10 The sum of the numbers is: 100.0 The average of the numbers is: 25.0 RESTART: P:/Cmpsc131/Programming Assignment solutions/PA13AverageofNumbersWithExceptions.py Enter a positive number to total or a negative number to calculate average: -2 You did not enter any numbers to average

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

What is cost plus pricing ?

Answered: 1 week ago

Question

1. What are the types of wastes that reach water bodies ?

Answered: 1 week ago

Question

Which type of soil has more ability to absorb water?

Answered: 1 week ago