Answer:
// program in Python
# function to find grade
def grade(t_score):
#grade A
if t_score >=90:
return 'A'
#grade B
elif t_score >=80 and t_score <90:
return 'B'
#grade C
elif t_score >=70 and t_score <80:
return 'C'
#grade D
elif t_score >=60 and t_score <70:
return 'D'
#grade F
else:
return 'F'
# function to find average score
def calc_average(test_score):
#variable to find sum
total = 0
for i in range(len(test_score)):
#calculate total score
total = total + test_score[i]
# find average
return total/float(len(test_score))
#array to store score
test_score = []
#read name of student
name = input("Enter student's name: ")
for i in range(8):
#read score
t_score = int(input("Enter the score {}: ".format(i+1)))
#add score to array
test_score.append(t_score)
#call function to find Average
averageScore = calc_average(test_score)
#print name of Student
print("Student Name: ", name)
#print each Score
for i in range(len(test_score)):
#print each Score and Grade
print("Score: ",test_score[i], "Letter Grade: ",grade(test_score[i]))
# print Average Score
print("Average Score: ", averageScore)
Explanation:
Read name of student from user.Then read 8 test scores from user. Call the function grade() to find the grade of a test score.Call the function calc_average() to find the average score of all test.Print each score and corresponding grade and print average score.
Output:
Enter student's name: Sam
Enter the score 1: 45
Enter the score 2: 98
Enter the score 3: 67
Enter the score 4: 86
Enter the score 5: 60
Enter the score 6: 77
Enter the score 7: 92
Enter the score 8: 32
Student Name: Sam
Score: 45 Letter Grade: F
Score: 98 Letter Grade: A
Score: 67 Letter Grade: D
Score: 86 Letter Grade: B
Score: 60 Letter Grade: D
Score: 77 Letter Grade: C
Score: 92 Letter Grade: A
Score: 32 Letter Grade: F
Average Score: 69.625