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
#4
Do you know how I could refactor this code to do that?

(Jan-26-2022, 11:58 AM)sean1 Wrote: How would I go about doctesting this? Output is following for e.g Maths Sam - 98

def Maximum():
    while True:
        print("Maximum marks: Please select a subject, (1) Maths (2) Physics (3) Biology (4) Geo (5) Chemistry (6) Total Marks (7) Menu")
        choice = input(" >> ")
        if choice == '1':
            # dictionary created which maps the students name to their score
            # Math
            mathtodict = dict(zip(Student, Maths_marks))
            maxmath = max(zip(mathtodict.values(), mathtodict.keys()))[1]
            print('Highest maths score: ' + maxmath + ' ' + '-' + ' ' + str(max(Maths_marks)))
        elif choice == '2':
            # Physics
            phystodict = dict(zip(Student, Physics_marks))
            maxphys = max(zip(phystodict.values(), phystodict.keys()))[1]
            print('Highest Physics score: ' + maxphys + ' ' + '-' + ' ' + str(max(Physics_marks)))
        elif choice == '3':
            # Biology
            biotodict = dict(zip(Student, Biology_marks))
            maxbio = max(zip(biotodict.values(), biotodict.keys()))[1]
            print('Highest Biology score: ' + maxbio + ' ' + '-' + ' ' + str(max(Biology_marks)))
        elif choice == '4':
            # Geography
            geogtodict = dict(zip(Student, Geog_marks))
            maxgeog = max(zip(geogtodict.values(), geogtodict.keys()))[1]
            print('Highest Geography score: ' + maxgeog + ' ' + '-' + ' ' + str(max(Geog_marks)))
        elif choice == '5':
            # Chemistry
            chemtodict = dict(zip(Student, Chemistry_marks))
            maxchem = max(zip(chemtodict.values(), chemtodict.keys()))[1]
            print('Highest Chemistry score: ' + maxchem + ' ' + '-' + ' ' + str(max(Chemistry_marks)))
        elif choice == '6':
            # calculates highest total marks scored across all subjects
            max_marks = 0
            for y in Total_marks:
              if y > max_marks:
                max_marks = y
                totaltodict = dict(zip(Student, Total_marks))
                totmax = max(zip(totaltodict.values(), totaltodict.keys()))[1]
            print('Highest total score: ' + totmax + ' ' + '-' + ' ' + str(max_marks))
        elif choice == '7':
            # exits the program and asks user if they want to return to menu or quit the program
            break

        else:
            print("Choice not found. Please choose again.")
            continue
Reply


Messages In This Thread
RE: Doctesting a function which prints a students name along with the maximum mark scored - by sean1 - Jan-30-2022, 09:14 AM

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