Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function score(file, student, hwk) that opens the file with name file (u

ID: 3694133 • Letter: W

Question

Write a function score(file, student, hwk) that opens the file with name file (use scores.csv, this is how excel file looks http://oi65.tinypic.com/25ja3rm.jpg). The function then returns the score the student had on the homework named hwk. You can assume that the homework names are in the very first line of the file (as they currently are), so you can search for them there (here, index() may be your friend).

5. (CSV, 10pt) Write a function score(file, student, hwk) that opens the file with name file (use scores.csv, which we saw in class). The function then returns the score the student had on the homework named hwk. You can assume that the homework names are in the very first line of the file (as they currently are), so you can search for them there (here, index() may be your friend). Python 3.43 Shell Eile Edit Shell Debug Options Window Help score ('scores.csv', 'Abbott,'hw1') student not found >>> score ( ' scores. csv ' , ' Edmonds ' , ' hw1' ) 87 >score ('scores.csv'Edmonds, 'hw12') no such column >>>Score (scores.csv 'Edmonds,'hw8) 96 577 Ln:1938 Col4

Explanation / Answer

def score(file,student,hwk):
f = open(file)
head = f.readline()
if(head[-1]==' '):
head = head[0:-1]
head = head.split(',')
try:
hw = head.index(hwk)
except:
return "No such column found"
for line in f.readlines():
line = line.split(',')
if(line[-1]==' '):
line=line[0:-1]
if(line[0]==student):
return line[hw]
return "Student not found"
print(score('scores.csv','Abbott','hw1'))
print(score('scores.csv','Edmonds','hw1'))
print(score('scores.csv','Edmonds','hw12'))
print(score('scores.csv','Edmonds','hw8'))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote