调试和修复评分舞者的代码

2024-09-29 17:13:55 发布

您现在位置:Python中文网/ 问答频道 /正文

这是背景:这是一个舞蹈比赛的规则,有6对夫妇和5名评委。对于gt分数,评委输入的分数和最高和最低的分数被删除,其余的被添加以创建总分。在

我的代码在第31行打印错误消息,说type error is not suscrible,假设它会对所有其他列表都这样说,请帮助我调试我的代码,生成一个工作解决方案,让用户为6对夫妇输入5次分数,然后删除最高和最低分数,并在文本文件的列表中显示所有内容。在

使用下面给出的()建议时,会出现以下错误消息: 回溯(最近一次呼叫): 文件“C:/Users/Samuel/AppData/Local/Programs/Python/Python36-32/text-saving分数.py“,第32行,英寸 listA=列表(coupa_judge1,coupa_judge2,coupa_judge3,coupa_judge4,coupa_judge5) TypeError:list()最多接受1个参数(给定5个) 我怎么解决这个问题

coupleA_judge1 = int(input("score couple A out of 10 (max 10, min 1)"))
coupleA_judge2 = int(input("score couple A out of 10 (max 10, min 1)"))
coupleA_judge3 = int(input("score couple A out of 10 (max 10, min 1)"))
coupleA_judge4 = int(input("score couple A out of 10 (max 10, min 1)"))
coupleA_judge5 = int(input("score couple A out of 10 (max 10, min 1)"))

coupleB_judge1 = int(input("score couple B out of 10 (max 10, min 1)"))
coupleB_judge2 = int(input("score couple B out of 10 (max 10, min 1)"))
coupleB_judge3 = int(input("score couple B out of 10 (max 10, min 1)"))
coupleB_judge4 = int(input("score couple B out of 10 (max 10, min 1)"))
coupleB_judge5 = int(input("score couple B out of 10 (max 10, min 1)"))

coupleC_judge1 = int(input("score couple C out of 10 (max 10, min 1)"))
coupleC_judge2 = int(input("score couple C out of 10 (max 10, min 1)"))
coupleC_judge3 = int(input("score couple C out of 10 (max 10, min 1)"))
coupleC_judge4 = int(input("score couple C out of 10 (max 10, min 1)"))
coupleC_judge5 = int(input("score couple C out of 10 (max 10, min 1)"))

coupleD_judge1 = int(input("score couple D out of 10 (max 10, min 1)"))
coupleD_judge2 = int(input("score couple D out of 10 (max 10, min 1)"))
coupleD_judge3 = int(input("score couple D out of 10 (max 10, min 1)"))
coupleD_judge4 = int(input("score couple D out of 10 (max 10, min 1)"))
coupleD_judge5 = int(input("score couple D out of 10 (max 10, min 1)"))

coupleE_judge1 = int(input("score couple E out of 10 (max 10, min 1)"))
coupleE_judge2 = int(input("score couple E out of 10 (max 10, min 1)"))
coupleE_judge3 = int(input("score couple E out of 10 (max 10, min 1)"))
coupleE_judge4 = int(input("score couple E out of 10 (max 10, min 1)"))
coupleE_judge5 = int(input("score couple E out of 10 (max 10, min 1)"))

listA = list(coupleA_judge1, coupleA_judge2, coupleA_judge3, coupleA_judge4, coupleA_judge5)
coupleA_lowest = min(listA)
coupleA_highest = max(listA)
scoresA = list.remove("coupleA_lowest", "coupleA_highest")
print(scoresA)

listB = list(coupleB_judge1, coupleB_judge2, coupleB_judge3, coupleB_judge4, coupleB_judge5)
coupleB_lowest = min(listB)
coupleB_highest = max(listA)
scoresB = list.remove("coupleB_lowest", "coupleB_highest")
print(scoresB)

listC = list(coupleC_judge1, coupleC_judge2, coupleC_judge3, coupleC_judge4, coupleC_judge5)
coupleC_lowest = min(listA)
coupleC_highest = max(listA)
scoresC = list.remove("coupleC_lowest", "coupleC_highest")
print(scoresA)

listD = list(coupleD_judge1, coupleD_judge2, coupleD_judge3, coupleD_judge4, coupleD_judge5)
coupleA_lowest = min(listD)
coupleA_highest = max(listD)
scoresA = list.remove("coupleD_lowest", "coupleD_highest")
print(scoresD)

listE = list(coupleE_judge1, coupleE_judge2, coupleE_judge3, coupleE_judge4, coupleE_judge5)
coupleE_lowest = min(listE)
coupleE_highest = max(listE)
scoresE = list.remove("coupleE_lowest", "coupleE_highest")
print(scoresE)


coupleA_lowest = min(listA)
coupleA_highest = max(listA)
list.remove("coupleA_lowest, coupleA_highest")

coupleA_total_score = 0
coupleB_total_score = 0
coupleC_total_score = 0
coupleD_total_score = 0
coupleE_total_score = 0

judges = ["judge 1", "judge 2", "judge 3", "judge 5", "total"]

couples = ["A", "B", "C", "D", "E"]

data =([coupleA_judge1, coupleA_judge2, coupleA_judge3, coupleA_judge4, coupleA_judge5, coupleA_total_score]
       [coupleB_judge1, coupleB_judge2, coupleB_judge3, coupleB_judge4, coupleB_judge5, coupleB_total_score]
       [coupleC_judge1, coupleC_judge2, coupleC_judge3, coupleC_judge4, coupleC_judge5, coupleC_total_score]
       [coupleD_judge1, coupleD_judge2, coupleD_judge3, coupleD_judge4, coupleD_judge5, coupleD_total_score]
       [coupleE_judge1, coupleE_judge2, coupleE_judge3, coupleE_judge4, coupleE_judge5, coupleE_total_score])
row_format ="{:>10}" * (len(judges)+1)
print (row_format.format("", *judges))
for score, row in zip(couples, data):
    f.write(row_format.format(score*row))

Tags: ofinputoutminmaxintscorecouple
2条回答

我认为丹提出的list()想法可能是个好的开始。另一个方法是对列表进行排序,然后绘制列表的子字符串(子字符串中包含的值小于最大值,大于最小值),而不是删除max和min,尽管删除max和min会更节省内存。在

当你在调用list()时,你肯定不需要使用list()方法。我不在我的电脑前,所以这不可能是它,但它对我很重要

相关问题 更多 >

    热门问题