Write a program that calculate the average of a group of tes…

Write a program that calculate the average of a group of test scores, where the lowest score is dropped. It should use the following functions: Validation: Do not accept test scores lower than 0 or higher than 100. Purchase the answer to view it

Answer

In order to create a program that calculates the average of a group of test scores, with the lowest score dropped, we can make use of several functions to ensure proper validation and accurate calculation. These functions will help us validate the input, calculate the average, and determine the lowest score.

First, we need to validate the input of each test score to ensure it falls within the acceptable range of 0 to 100. This can be accomplished by creating a validation function that takes in a test score as a parameter and returns true if it is in the valid range, or false otherwise. This function can be implemented using an if statement to check whether the score is less than 0 or greater than 100.

Next, we need a function to calculate the average of the test scores, excluding the lowest score. This function will take in a list of test scores as a parameter and return the average. To determine the lowest score, we can use the built-in min() function on the list of scores. Then, we can use a combination of sum() and len() functions to calculate the sum of the scores and the number of scores, respectively. Finally, we can subtract the lowest score from the sum and divide by the total number of scores minus one to get the average.

To tie everything together, we can create a main function that prompts the user for the number of test scores they would like to enter. This function will then use a loop to iterate through each score, calling the validation function to ensure it is within the valid range. If a score is valid, it will be added to a list of scores. Once all scores have been entered, the main function will call the average calculation function, passing in the list of scores, and display the resulting average.

Here is an example implementation of the program in Python:

“`python
def validate_score(score):
if score < 0 or score > 100:
return False
return True

def calculate_average(scores):
lowest_score = min(scores)
sum_of_scores = sum(scores) – lowest_score
num_of_scores = len(scores) – 1
average = sum_of_scores / num_of_scores
return average

def main():
num_of_scores = int(input(“Enter the number of test scores: “))
scores = []
for i in range(num_of_scores):
score = float(input(f”Enter test score {i+1}: “))
if validate_score(score):
scores.append(score)
else:
print(“Invalid score. Please try again.”)
i -= 1
average = calculate_average(scores)
print(f”The average of the test scores, excluding the lowest score, is: {average}”)

main()
“`

This program allows the user to enter the number of test scores they want to calculate the average for. It then prompts them to enter each score one by one, validating each score before adding it to the list. After all of the scores have been entered, the program calculates the average and displays the result.

Do you need us to help you on this or any other assignment?


Make an Order Now