Выбор максимальных баллов из списка питонов

1

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

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
    Осторожно: scoresA2 = listA2 не выполняет то, что вы ожидаете - он не копирует список. cf nedbatchelder.com/text/names.html для получения дополнительной информации.
Теги:
list
python-3.x

1 ответ

2
Лучший ответ

Ваш код устраняет 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)))

Ещё вопросы

Сообщество Overcoder
Наверх
Меню