Python Forum
Doctesting a function which prints a students name along with the maximum mark scored
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Doctesting a function which prints a students name along with the maximum mark scored
#6
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!

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)
Reply


Messages In This Thread
RE: Doctesting a function which prints a students name along with the maximum mark scored - by Pedroski55 - Feb-01-2022, 12:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  i scored 1/8 on python assessment where did i mess up? SAVAGEMIKE 5 590 Jan-18-2024, 02:50 PM
Last Post: Pedroski55
  zfill prints extra et the end of a var tester_V 4 849 Mar-24-2023, 06:59 PM
Last Post: tester_V
  Mark outlook emails as read using Python! shane88 2 6,450 Feb-24-2022, 11:19 PM
Last Post: Pedroski55
  variable prints without being declared. ClockPillow 2 1,771 Jul-11-2021, 12:13 AM
Last Post: ClockPillow
  python prints none in function output chairmanme0wme0w 3 2,157 Jul-07-2021, 05:18 PM
Last Post: deanhystad
  Something wrong with the quotation mark in dictionary definition Mark17 1 1,958 Jan-29-2021, 03:34 PM
Last Post: buran
  Output prints Account.id at the end? LastStopDEVS 5 2,718 Dec-19-2020, 05:59 AM
Last Post: buran
  Try/Exept prints only ones tester_V 11 3,738 Nov-03-2020, 02:38 AM
Last Post: tester_V
  How to mark duplicate rows in pandas Mekala 3 2,503 Sep-17-2020, 11:32 PM
Last Post: scidam
  loop only prints last character. mcmxl22 1 1,674 Feb-17-2020, 02:36 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020