List = [name, lines.split(":")[1]] Latest_scores = (lines.split(":")[1][-7:]) Highscore = max(latest_scores) Print(highscore)
Out of: 9,10,2, It says the highestvalue is 9, not 10 as if it is ignoring the two digit number.
答案 0 :(得分:7)
You should convert the scores to integers, e.g. with map(int, Latest_scores)
. Strings are compared in alphabetic order, where 9 comes last and therefore is the maximum.
EDIT: From your comments it seems that Latest_scores
is just a string. That would mean you're trying to find a maximum in a string. The max
function then returns the "highest" character in the string. To make this work correctly, you have to split the string by the ,
character:
Latest_scores = lines.split(":")[1][-7:].split(",")
Highscore = max(map(int, Latest_scores))
Print(Highscore)