Выбор максимальных баллов из списка питонов - PullRequest
0 голосов
/ 19 сентября 2018

Я запустил код, в котором я участвую в различных раундах танцевального конкурса и должен исключать две худшие пары в каждом раунде.

В настоящее время я нахожусь на втором этапе, и я заставляю пользователя вводить его /ее собственные результаты в качестве судей, но я не могу удалить две худшие пары из списка баллов, который ввел пользователь.

Это то, что я пока имею:

cA2_judge1 = int(input("score couple A out of 10"))
cA2_judge2 = int(input("score couple A out of 10"))
cA2_judge3 = int(input("score couple A out of 10"))
cA2_judge4 = int(input("score couple A out of 10"))
cA2_judge5 = int(input("score couple A out of 10"))
print("")
cC2_judge1 = int(input("score couple C out of 10"))
cC2_judge2 = int(input("score couple C out of 10"))
cC2_judge3 = int(input("score couple C out of 10"))
cC2_judge4 = int(input("score couple C out of 10"))
cC2_judge5 = int(input("score couple C out of 10"))
print("")
cD2_judge1 = int(input("score couple D out of 10"))
cD2_judge2 = int(input("score couple D out of 10"))
cD2_judge3 = int(input("score couple D out of 10"))
cD2_judge4 = int(input("score couple D out of 10"))
cD2_judge5 = int(input("score couple D out of 10"))
print("")
cF2_judge1 = int(input("score couple F out of 10"))
cF2_judge2 = int(input("score couple F out of 10"))
cF2_judge3 = int(input("score couple F out of 10"))
cF2_judge4 = int(input("score couple F out of 10"))
cF2_judge5 = int(input("score couple F out of 10"))


listA2 = [cA2_judge1, cA2_judge2, cA2_judge3, cA2_judge4, 
cA2_judge5]
listA2.remove(min(listA2))
listA2.remove(max(listA2))
scoresA2=listA2
print("-------------------------")
print(".                       .")
print("Couple A scored",scoresA2)
print("This makes their total", sum(scoresA2))

listC2 = [cC2_judge1, cC2_judge2, cC2_judge3, cC2_judge4, 
cC2_judge5]
listC2.remove(min(listC2))
listC2.remove(max(listC2))
scoresC2=listC2
print("-------------------------")
print(".                       .")
print("Couple C scored",scoresC2)
print("This makes their total", sum(scoresC2))

listD2 = [cD2_judge1, cD2_judge2, cD2_judge3, cD2_judge4, 
cD2_judge5]
listD2.remove(min(listD2))
listD2.remove(max(listD2))
scoresD2=listD2
print("-------------------------")
print(".                       .")
print("Couple D scored",scoresD2)
print("This makes their total", sum(scoresD2))

listF2 = [cF2_judge1, cF2_judge2, cF2_judge3, cF2_judge4, 
cF2_judge5]
listF2.remove(min(listF2))
listF2.remove(max(listF2))
scoresF2=listF2
print("-------------------------")
print(".                       .")
print("Couple F scored",scoresF2)
print("This makes their total", sum(scoresF2))

listR2 = [sum(scoresA2), sum(scoresC2), sum(scoresD2), 
sum(scoresF2)]
listR2.remove(min(listR2))
listR2.remove(min(listR2))
print("")
print("")
print("This leaves us with the highest score of",max(listR2))

1 Ответ

0 голосов
/ 19 сентября 2018

Ваш код исключает 2 худшие оценки , но теряет ссылку на пары.Вам следует использовать список пар (couple, score), отсортировать его по счету и затем удалить 2 самые младшие пары.Таким образом, вы можете отобразить, какие пары остались.

Вы можете использовать:

listR2 = [('A', sum(scoresA2)), ('C', sum(scoresC2)), ('D', sum(scoresD2)), 
('F', sum(scoresF2))]
listR2 = sorted(listR2, key = lambda x: x[1], reverse = True)[:-2]
print("Remaining couples are",
    " and ".join(("{0} with a total score of {1}".format(*i) for i in listR2)))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...