In: Computer Science
Python Programming Exercise Scenario:
Write a program that asks the user to enter scores the number is based on what the user wants to enter. The program will display a letter grade and associated message for each score, based on the table below, and the average score. The program will not contain any repeated code and have a minimum of two functions besides Main.
Score Letter Grade Message
90 – 100 A Excellent work
89 – 80 B Nice job
79 – 70 C Not bad
69 – 60 D Room for improvement
Below 60 F Go back and review
Code
def getscore(n):
l=[]
i=0
while(i<n): #loop till inputs n valid numbers
v=int(input())
if v<0 or v>100: #invalid score
print("Enter valid score")
else:
grade(v)
l.append(v)
i=i+1
return l #return the list
def grade(n):
if n>=90 and n<=100:
print("A","Excellent")
elif n>=80 and n<=89:
print("B","Nice job")
elif n>=70 and n<=79:
print("C","Not bad")
elif n>=60 and n<=69:
print("D","Room for improvement")
else:
print("F","Go back and review")
if __name__=="__main__":
print("Enter the number of scores: ")
n=int(input()) #input number of scores
print("Enter the scores: ")
l=getscore(n) #print grade and message
print('Average is: ')
print(sum(l)/n) #print averagw
Terminal Work
.