I have a file with several lists of names with scores. Ex: Foo 3 4 5 4 3 80 90 40
I need to split the file and then make it so I can take the numbers and calculate averages, so the numbers need to not be seen by Python as strings. This is what I'm having trouble on. This is the following code I have:
>>> def exchange(grades):
grades[grades.index(min(grades))] = max(grades)
return grades
>>> def average_scores(grades, x, y):
global average
average = 0
count = 0.0
for i in grades[x:y]:
average = average + int(i)
count = count + 1
average = average/count
return average
>>> def change_grades(grades, x):
for i in range(x):
exchange(grades)
>>> def letter_grade(num):
if num < 60:
return "F"
elif num < 70:
return "D"
elif num < 80:
return "C"
elif num < 90:
return "B"
else:
return "A"
>>> def weighted_grade():
quiz_grades = average_scores(grades, 0, 14)
prog_assg = average_scores(grades, 15, 19)
exams = average_scores(grades, 20, 21)
final_exam = grades[22]
participation = grades[23]
weighted_average = quiz_grades * 10 *.3 + prog_Assg * .3 + exams * .2 + final_exam * .2 + participation
num = round(weighted_average)
return num
>>> def main():
global myfile
global myfile2
myfile = open("C:\Python27\input.txt", "rU")
myfile2 = open ("C:\Python27\my.output.txt", "w")
global hold
global hold2
hold = 0
hold2 = []
global grades
grades = []
make_list()
for i in (hold2.split()[0:25]):
grades.append(i)
name = grades.pop(0)
for i in grades:
i = int(i)
times_droped = raw_input("how many grades would you like to change? (use numbers)")
int(times_droped)
change_grades(grades, times_droped)
final_output = []
final_output.append(name)
final_output.append(weighted_grade())
final_output.append(letter_grade())
myfile2.close()
myfile.close()
>>> def make_list():
for line in myfile:
hold = line
hold2.append(hold)
return hold2
>>> if __name__ == '__main__':
main()
With the following error:
Traceback (most recent call last):
File "<pyshell#204>", line 2, in <module>
main()
File "<pyshell#199>", line 13, in main
for i in (hold2.split()[0:25]):
AttributeError: 'list' object has no attribute 'split'