Respuesta :
Answer:
I am writing the program in C++ and Python.
C++ code:
#include <iostream> // for input output functions
using namespace std; // identifies objects like cin cout
int main() //start of main() function body
{ // test scores variables are declared along with average and sum variables
double test_score1, test_score2, test_score3, test_score4, test_score5, average, sum;
cout << "Enter 5 test scores: \n"; //prompts user to enter 5 test scores
cin >> test_score1 >> test_score2 >> test_score3 >> test_score4 >> test_score5; //reads values of five test scores entered by user
sum = test_score1 + test_score2 + test_score3 + test_score4 + test_score5; // calculates the sum of the five test scores
average = sum / 5; //computes the average of five test scores
cout << "The average test score is: " << average;
//displays the computer average of the five test scores entered by the user
}
Explanation:
The program prompts the user to enter the values of 5 test scores. It the calculates the sum of all these 5 input test scores and stores the result in sum variable. In order to compute average test score the sum of these 5 test scores is divided by the total number of test scores that is 5 and the result is stored in average variable. Lastly it displays the average by displaying the value of the average stored in the average variable.
Python Program:
num=5 # total number of test scores
list=[] #list to store values of 5 test scores
for i in range(0,num): #loop to enter values of test scores
#prompts user to enter values for 5 test scores
test_scores =int(input("Enter the five test scores"))
list.append(test_scores) #appends the input test scores in the list
average=sum(list)/num #calculates sum of the values stored in list and #divides the value of sum with the total number of test scores i.e. 5
print("Average test score is: ",round(average,2))
#displays average of the five test scores rounding up to two decimal places
Explanation:
This is a small program in Python to compute average test score. If you want to take separate input for each of the five test scores you can use the following program:
#takes value for each test score seperately from user
testScore1 = int(input('Enter 1st test score: '))
testScore2 = int(input('Enter 2nd test score : '))
testScore3 = int(input('Enter 3rd test score : '))
testScore4 = int(input('Enter 4th test score : '))
testScore5 = int(input('Enter 5th test score : '))
#calculates sum of each test score
sum = (testScore1 + testScore2 + testScore3 + testScore4 + testScore5)
#method to compute average test score
def average(sum):
return sum / 5 #divide value of sum with total number of test scores
#calls average function to display average test score using print statement
print("average test score is: " , average(sum))
The programs along with their outputs is attached in the screenshots.


