Jan-26-2022, 11:58 AM
(This post was last modified: Jan-26-2022, 12:21 PM by Gribouillis.)
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
Gribouillis write Jan-26-2022, 12:21 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.