Consider the file score below, which provides the scores of each student in five
ID: 3671546 • Letter: C
Question
Consider the file score below, which provides the scores of each student in five different assessments.
$ cat score
pchen72 50 71 55 93 115
jmaszk 45 76 49 88 102
bvbui 59 78 53 96 145
mtcrowle 33 65 39 82 100
mrchave3 54 77 56 98 158
Write a python script that computes the final percentage score for each student, as well as the class average
The max score is 450 and must be set as constant.
The output should be (round the score to nearest integer):
Total number of records: 5
Final score for pchen72 = 85%
Final score for jmaszk = 80%
…
Class Average = 86%
The header line should show: Final Score computation
Explanation / Answer
data = []
with open('score.txt') as f:
for line in f:
split_line = [i for i in line.split() ]
data.append(split_line)
length = len(data)
class_percentage = 0
print " Final Score computation "
print "Total number of records:",length
for student in data:
score = student[1:] #take out all the score part
score = map(int, score) #to convert string into int
percentage = (sum(score)*100.0/450.0)
class_percentage += percentage
print "Final score for ",student[0]," = %.0f"%percentage,"%"
class_percentage /= length
print "Class Average = %.0f"%class_percentage,"% "
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.