Question: 12.5 Python Assignment: Grade Lookup You will be given a .csv file, scores.csv, similar to the file shown in the example in section 12.4. The
12.5 Python Assignment: Grade Lookup
You will be given a .csv file, "scores.csv", similar to the file shown in the example in section 12.4. The first row will contain row headers: name, score1, score2, score3, score4, score5. Each row after will represent those 5 scores for each student.
Write a function that takes a string for the name as a parameter and returns their grade, from A to F. Use the standard scale of 90 and above is an A, 80 and above is a B, etc. Do not weight the scores, just take the average of the 5 scores. If the name is not found, return 'unknown'.
Loop on each row, as shown in 12.4. The name will be in row[0]
If the name matches the parameter, then calculate the average of the next 5 cells in the row.
Return a grade from 'A' through 'F', depending on the average
If the program makes it to the end of the function without returning a grade, that means the name was not found. Return 'unknown'.
Write a main function that does the following:
input a string for the name
loop until the name is 'quit'
print the calculated grade for that name
input the next name
Use the following structure for your code:
import csv def calculateGrade(searchName): #open file #open csv reader #loop on each row #skip first row #if the name matches #sum up the rest of the cells #calculate the average #return a letter grade based on the average #return 'unknown' (if the program gets here, the name was not found) def main(): #input name #while condition: #print grade #input name if __name__ == '__main__': main()
A sample output is as follows:
name: Jon Snow C name: Arya Stark A name: Sansa Stark D name: Ned Stark B name: Theon Greyjoy F name: Roger Rabbit unknown name: quit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
