29.7k views
4 votes
Write a program named TestScoreList that accepts eight int values representing student test scores. Display each of the values along with a message that indicates how far it is from the average. An example of how the results should be output is as follows:

Test # 0: 89 From average: 6

Test # 1: 78 From average: -5

User Pi Pi
by
5.4k points

1 Answer

3 votes

Final answer:

The program 'TestScoreList' calculates the average of eight int values representing student test scores, then displays each score with a message indicating its difference from the average. The program iterates through inputted scores to accumulate the total, computes the average, and displays the difference for each score in relation to the average.

Step-by-step explanation:

The program TestScoreList calculates the average of eight student test scores and then displays each test score along with how far it is from the average. To accomplish this, the program will sum all the scores, calculate the average, and then iterate through the list of scores to determine the difference between each score and the average. Below is an example of such a program coded in a general-purpose programming language:


scores = []
for i in range(8):
score = int(input(f'Enter score for test # {i}: '))
scores.append(score)

average = sum(scores) / len(scores)
print(f'Average score: {average}')

for i, score in enumerate(scores):
print(f'Test # {i}: {score} From average: {score - average}')

This program begins by creating an empty list named scores. It then uses a loop to prompt the user for eight test scores, which it adds to the list. Next, it calculates the average score and prints it. Finally, it uses another loop to print each score along with the difference from the average.

User RunRyan
by
6.1k points