In: Computer Science
Please write in Python code please:
Write a program that asks the user to enter 5 test
scores between 0 and 100. The program should display a letter grade
for each score and the average test score. You will need to write
the following functions, including main:
calc_average – The function should accept a list of 5 test scores
as an input argument, and return the average of the scores
determine_grade – The function should accept a test score as an
argument, and return a letter grade for the score based on the
grading scale below:
85 or over HD
75-84 D
65-74 C
50-64 P
<50 F
# definig calc_average() function
def calc_average( sub1,sub2,sub3,sub4,sub5):
average= (sub1+sub2+sub3+sub4+sub5)/5
print("The average test score is : "+str(average))
# str() is used to explicitly convert 'float' object to string
# definig determine_grade function
def determine_grade( userScore):
if(userScore < 50 ):
return "F"
elif(userScore < 65 ):
return "P"
elif(userScore < 75 ):
return "C"
elif(userScore < 85 ):
return "D"
elif(userScore < 101 ):
return "HD"
# definig askForMarks function which will ask for input subject
marks
def askForMarks():
sub1=float(input("Enter Marks of 1st Subject : "))
sub2=float(input("Enter Marks of 2nd Subject : "))
sub3=float(input("Enter Marks of 3rd Subject : "))
sub4=float(input("Enter Marks of 4th Subject : "))
sub5=float(input("Enter Marks of 5th Subject : "))
return sub1,sub2,sub3,sub4,sub5
# definig printResult function which will print the output
result
def printResult(sub1,sub2,sub3,sub4,sub5):
print("\nMarks\tLetter Grade")
print(" "+str(sub1)
+"\t\t"+determine_grade(sub1)+"\n",\
str(sub2) +"\t\t"+determine_grade(sub2)+"\n",\
str(sub3) +"\t\t"+determine_grade(sub3)+"\n",\
str(sub4) +"\t\t"+determine_grade(sub4)+"\n",\
str(sub5) +"\t\t"+determine_grade(sub5)+"\n")
def main():
#call to askForMarks function
sub1, sub2, sub3, sub4, sub5 = askForMarks()
#call to printResult function
printResult(sub1, sub2, sub3, sub4, sub5)
#call to calc_average function
calc_average(sub1, sub2, sub3, sub4, sub5)
main()
'''
OUTPUT
Enter Marks of 1st Subject : 60
Enter Marks of 2nd Subject : 63
Enter Marks of 3rd Subject : 100
Enter Marks of 4th Subject : 32
Enter Marks of 5th Subject : 70
Marks Letter Grade
60.0 P
63.0 P
100.0 HD
32.0 F
70.0 C
The average test score is : 65.0
'''