I am supposed to get input for a few bowlers, and their scores. Then output the top score, lowest score and the average team score. My code will not sort the scores correctly.

def myMax(list): 
    maxVal= -100000 
    maxIndex = -1 
    for i in range(len(list)): 
        if list[i] > maxVal: 
            maxVal = list[i] 
            maxIndex = i 
nsList = []
while True:
    temp = input("Enter Bowler and thier score by Name, Score ")
    split_list = temp.split(' ')

#end of loop
#print ("The high score is ", maxVal)
print ("The high score is", (nsList[0]))
print ("Sorry" , nsList[-1], "has the lowest score")

1 Answers

Steve On

You can sort your list in descending order with the following:

nsList.sort(key=lambda v : v[1], reverse=True)

Put this after your for loop that builds nsList, and you'll be good. You don't need your myMax function.

Btw, you should make it clear what your input format is in your prompt message. You currently say: "Enter Bowler and thier score by Name, Score ". This suggests that you should put a comma between Name and Score, but your code requires a single space character between them to work correctly. Alternately, you could beef up your input parsing code to be more flexible in the input it takes.