Nov-16-2019, 08:40 PM
Hello. I'm working on a problem where there is a file that contains the name and 5 test scores for 5 students. I have to use python 2.7 even though I know it is obsolete.
File:
this is the code that I have so far:
The part I'm having trouble with is
File:
Quote: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
this is the code that I have so far:
#!/usr/bin/python import string from string import split import math num_lines = 0 with open('score') as f: for line in f.readlines(): data=line.split() num_lines += 1 scores1 = int(data[1]) scores2 = int(data[2]) grade = scores1 + scores2 print ("Total Number of Records: %i") %num_lines print(grade)
The part I'm having trouble with is
scores1 = int(data[1]) scores2 = int(data[2])Sure, I could do this with all 5 scores and do the math required for the problem that way but what I was trying to do was clean it up with something like this:
score = int(data[1:]but I keep getting all types of errors. I even tried
data[1:5]and still doesn't work. Any ideas?