In: Computer Science
Write a PYTHON program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name.
Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student.
determine_grade - this function should accept a test score average as an argument and return a letter grade for the score based on the following grading scale: 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F.
Here is the code:
# this function should accept 8 test scores as arguments and return the average of the scores per student
def calc_average(scores):
avg_score = sum([item for item in scores]) / len(scores)
return(avg_score)
# this function should accept a test score average as an argument and return a letter grade for the score
def determine_grade(test_score_average):
if(test_score_average >= 90):
return('A')
elif(test_score_average >= 80 and test_score_average < 89):
return('B')
elif(test_score_average >= 70 and test_score_average < 79):
return('C')
elif(test_score_average >= 60 and test_score_average < 69):
return('D')
else:
return('F')
name = input('Enter your name: ') # collecting name
marks = list()
for loop1 in range(8): # collecting marks
marks.append(int(input('Please enter your marks for ' + str(loop1+1) +' subject out of 100: ')))
# calling the functions:
avg_score = calc_average(marks)
print('\navg_score = ',avg_score)
print('Grade: ',determine_grade(avg_score))
Here is the output:
For any doubts, please comment below.