question archive 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)
Subject:Computer SciencePrice:2.87 Bought7
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. There are 12 students in the class.
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
Answer:
def determine_grade(score):
if score >=90:
return 'A'
elif score >=80 and score <90:
return 'B'
elif score >=70 and score <80:
return 'C'
elif score >=60 and score <70:
return 'D'
else:
return 'F'
def calc_average(scores):
total = 0
for i in range(len(scores)):
total = total + scores[i]
return total/float(len(scores))
scores = []
name = input("Enter the student name: ")
for i in range(8):
score = int(input("Enter the score: "))
scores.append(score)
averageScore = calc_average(scores)
print("Student Name: ", name)
for i in range(len(scores)):
print("Score: ",scores[i], "Letter Grade: ",determine_grade(scores[i]))
print("Average Score: ", averageScore)
Output:
$python3 main.py Enter the student name: 55 Enter the score: 66 Enter the score: 77 Enter the score: 88 Enter the score: 99 Enter the score: 22 Enter the score: 33 Enter the score: 44 Student Name: Suresh Score: 55 Letter Grade: F Score: 66 Letter Grade: D Score: 77 Letter Grade: C Score: 88 Letter Grade: B Score: 99 Letter Grade: A Score: 22 Letter Grade: F Score: 33 Letter Grade: F Score: 44 Letter Grade: F Average Score: 60.5
PFA