Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I'm not sure how to do assignment 13 which stems from assignment 4(which I did), so I'll attach pics of both. Assignment 13 . Assignment
I'm not sure how to do assignment 13 which stems from assignment 4(which I did), so I'll attach pics of both.
Assignment 13
.
Assignment 4
Grade Average with Exceptions 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 a number, e-g. fred, causing a ValueError, 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.64 Shell File Edit Shel 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. 2z RESTART: P:/Cmpsc131/Programming Assignment Solutions/PA13 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 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 avera The sum of the numbers is: 100.0 The average of the numbers is: 25.0 AverageofNumbersWithExceptions.py negative number to calculate average: 30 ge: -10 RESTART : P:/Cmpsc131/Programing Assignment Solutions / PA13AverageofNumberswithExceptions Enter a positive number to total or a negative number to calcula You did not enter any numbers to average. .Py te average: -2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started