I've created the code however I want to be able to change it so that the teacher views the entire class' results rather than a specific student.
Here is my code.
form = input('What form would you like to view? G, H or J? ') name = input("Which student's results do you want to view? ") if form == 'G': o = open('G.txt') contents = o.read() if name in contents: with open('G.txt') as myFile: for num, line in enumerate(myFile, 1): if name in line: print("Number of '" + name + "' in file = ", contents.count(name))
G = open('G.txt','r')
for line in G:
results = line.split(',')
num_of_name = contents.count(name)
while num_of_name >3:
a = int(results.index(name))
b = int(a + 1)
results.remove(results[b])
results.remove(results[a])
num_of_name = int(num_of_name) - 1
indices = [i for i, x in enumerate(results) if x == name]
c = len(indices)
if c == 3:
d = [results[indices[0] + 1],results[indices[1] + 1],results[indices[2] + 1]]
print(str(name) + ' has got ' +str(results[indices[0] + 1])+', ' +str(results[indices[1] + 1])+' and ' +str(results[indices[2] + 1]))
elif c == 2:
d = [results[indices[0] + 1],results[indices[1] + 1]]
print(str(name) + ' has got ' +str(results[indices[0] + 1])+' and ' +str(results[indices[1] + 1]))
elif c == 1:
d = [results[indices[0] + 1]]
print(str(name) + ' has got ' +str(results[indices[0] + 1]))
else:
print('This person has not done any quizzes')
decision = input('Alphabetical order, highest score, average score? 1, 2 or 3? ')
if decision == '1':
e = sorted(d)
print(name)
if decision == '2':
print('The highest score ' +name +' got was ' +max(d) +'.')
if decision == '3':
e = int(results[indices[0] + 1]) +int(results[indices[1] + 1]) +int(results[indices[2] + 1])
f = e/int(len(d))
print(name +"'s average score was " + str(f) + '.')
G.close()