1. Engineering
  2. Computer Science
  3. function name average parameters numgrades int returns float...

Question: function name average parameters numgrades int returns float...

Question details

Function name : average

Parameters : num_grades (int)

Returns: float or string

Description : Write a function called average which takes in an int representing the number of times a user will be prompted to enter a test grade with the string 'Please enter a test grade: ' . With each grade the user enters, the program should keep updating the overall average test grade. If the average grade falls below a 70, return the overall average test grade rounded to one decimal place even if the user has not entered num_grades test grades. For example in the test case shown below, average(4), the function returned the average 57.5 even though the user had not yet entered 4 test grades since the average fell below a 70. Otherwise, the function should continue until the user has entered num_grades test grades and return the overall average rounded to one decimal place. If num_grades is 0, the function should return the string "Not enough grades to calculate average." Your function needs to use a while loop. Assume that the values of the test grades will be greater than or equal to zero.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution