Feb-01-2022, 12:20 PM
Where are you getting your data from? Excel? MySQL?
Assume Excel, then I would have an Excel file with a sheet for each subject and one sheet for totals. Each sheet would have the columns:
student_number, name, score1, score2, .... , scoreX
No two student numbers can be the same, so they are safer than names.
Hope you don't have millions of data!
Assume Excel, then I would have an Excel file with a sheet for each subject and one sheet for totals. Each sheet would have the columns:
student_number, name, score1, score2, .... , scoreX
No two student numbers can be the same, so they are safer than names.
Hope you don't have millions of data!
import openpyxl path2file = '/home/pedro/temp/' scoresXL = 'getmax.xlsx' sourceFile = openpyxl.load_workbook(path2file + scoresXL) sourceSheetNames = sourceFile.sheetnames for sheet in sourceSheetNames: print('Which maximum do you want?', sheet) mymax = input('Copy and paste one of the above sheet names here ... ') # maybe you want to change this for equally high scores or add the name def getData(sheet): high_score = 0 maxRow = sourceFile[sheet].max_row + 1 # + 1 makes sure you get the last row maxCol = sourceFile[sheet].max_column + 1 # ditto for rowNum in range(2, maxRow): for col in range(3, maxCol): score = sourceFile[sheet].cell(row=rowNum, column=col).value if score > high_score: high_score = score studinr = sourceFile[sheet].cell(row=rowNum, column=1).value return (studinr, high_score) tup = getData(mymax) print('The student with student number', tup[0], 'achieved', tup[1], 'in', mymax)