• Define a function to prompt the user to enter valid scores until they enter a sentinel value -999. Have this function both create and return a list of these scores. Do not store -999 in the list! • Have main( ) then pass this the list to a second function which traverses the list of scores printing them along with their appropriate grade.
I am having trouble with the getGrade function, it gives the error for i in grades: name 'grades' is not defined.
def main():grade = getScore()print(getGrade(grade))def getScore():grades = []score = int(input("Enter grades (-999 ends): "))while score != -999:grades.append(score)score = int(input("Enter grades (-999 ends): "))return gradesdef getGrade(score):best = 100for i in grades:if score >= best - 10:print(" is an A")elif score >= best - 20:print(score, " is a B")elif score >= best - 30:print(score, " is a C")elif score >= best - 40:print(score, " is a D")else:print(score, "is a F")main()