You are to write a program that will process students and their grades. For each student the program will read in a student’s name. It should also read in 10 test scores for the student and calculate his or her average. You must read the scores using a loop. The program should output the student’s name, average and letter grade. The average should be displayed accurate to 1 decimal digit.
Letter grades are assigned based on the scale:
90-100 A
80-89 B
70-79 C
60-69 D
below 60 F
You do not know how many students there are but there will be a sentinel for the student names. The sentinel is “done”.
I will run the program on the following data:
Mary Jones
90 90 78 89 90 55 66 90 90 90
Sam Iam
60 66 67 70 45 55 46 65 23 44
Mary Poppins
90 90 90 90 90 90 99 99 99 90
James Brown
80 88 78 89 85 84 82 82 83 83
done
So, make sure this data works on your end too.
Here is the code:
while(True):
name = input('Please enter name: ')
if(name == 'done'):
break
else:
marks = list()
for loop1 in range(10):
marks.append(int(input('Please enter marks of ' + str(loop1+1) + ' subject: ')))
avg_marks = sum(marks) / len(marks)
# finding grade
if(avg_marks >= 90):
grade = 'A'
elif(avg_marks >= 80 and avg_marks < 90):
grade = 'B'
elif(avg_marks >= 70 and avg_marks < 80):
grade = 'C'
elif(avg_marks >= 60 and avg_marks < 70):
grade = 'D'
else:
grade = 'F'
print("\nStudent's name: ", name)
print('Average: ',avg_marks)
print('Grade: ',grade)
Here is the results:
For any doubts, please comment below.
Get Answers For Free
Most questions answered within 1 hours.