def menuInsertParticipantAtPosition(scoreList): s1 = utilities.readInteger("Score 1: ") s2 = utilities.readInteger("Score 2: ") s3 = utilities.readInteger("Score 3: ") pos = utilities.readInteger("Position: ") printCommandResult(commands.insertAtPosition(scoreList, [str(s1), str(s2), str(s3), 'at', str(pos)]))
def menuListCommand(scoreList): sign = readCommand("Sign (<, =, >): ") score = utilities.readInteger("Score: ") # sign[0], because readCommand returns a command name and the arguments # hacks everywhere printCommandResult(commands.listCommand(scoreList, [sign[0], str(score)]))
def runMenu(): scoreList = [] # used for testing testInsertValuesNoOrder(scoreList) while True: printMenu() option = utilities.readInteger(">> ") if option == 1: menuAddParticipantToList(scoreList) elif option == 2: menuInsertParticipantAtPosition(scoreList) elif option == 3: menuRemoveParticipantAtPosition(scoreList) elif option == 4: menuRemoveFromIToJ(scoreList) elif option == 5: menuReplaceScore(scoreList) elif option == 6: printCommandResult(commands.listCommand(scoreList, "")) elif option == 7: printCommandResult(commands.listCommand(scoreList, ["sorted"])) elif option == 8: menuListCommand(scoreList) elif option == 9: menuAvgScores(scoreList) elif option == 10: menuMinScores(scoreList) elif option == 11: menuTopNCommand(scoreList) elif option == 12: menuTopNCommandByProblemId(scoreList) elif option == 13: menuRemoveLessEquGreaterThan(scoreList) elif option == 14: printCommandResult(commands.undo(scoreList, "")) elif option == 15: exit() else: print("Unknown option!")
def menuTopNCommand(scoreList): participantsLimit = utilities.readInteger("How many participants do you want to see? ") printCommandResult(commands.topCommand(scoreList, [str(participantsLimit)]))
def menuTopNCommandByProblemId(scoreList): participantsLimit = utilities.readInteger("How many participants do you want to see? ") problemNo = utilities.readInteger("Problem number (1, 2, 3): ") printCommandResult(commands.topCommand(scoreList, [str(participantsLimit), 'P' + str(problemNo)]))
def menuRemoveLessEquGreaterThan(scoreList): sign = readCommand("Sign (<, =, >): ") score = utilities.readInteger("Score: ") printCommandResult(commands.removeLessEquGreaterThan(scoreList, sign[0], score))
def menuRemoveFromIToJ(scoreList): pos1 = utilities.readInteger("Position 1: ") pos2 = utilities.readInteger("Position 2: ") printCommandResult(commands.removeFromIToJ(scoreList, pos1, pos2))
def menuRemoveParticipantAtPosition(scoreList): pos = utilities.readInteger("Position: ") printCommandResult(commands.removeFromPosition(scoreList, pos))
def menuAddParticipantToList(scoreList): s1 = utilities.readInteger("Score 1: ") s2 = utilities.readInteger("Score 2: ") s3 = utilities.readInteger("Score 3: ") printCommandResult(commands.addScore(scoreList, [str(s1), str(s2), str(s3)]))
def menuReplaceScore(scoreList): pos = utilities.readInteger("Position: ") problemNo = utilities.readInteger("Problem number (1, 2, 3): ") score = utilities.readInteger("Score: ") printCommandResult(commands.replaceScore(scoreList, [str(pos), 'P' + str(problemNo), 'with', str(score)]))
def menuAvgScores(scoreList): pos1 = utilities.readInteger("Position 1: ") pos2 = utilities.readInteger("Position 2: ") printCommandResult(commands.avgScores(scoreList, [str(pos1), 'to', str(pos2)]))