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

时间:2017-10-04 18:12:41

标签: python

这是背景:该代码适用于6对夫妇和5名评委的舞蹈比赛。为评分输入得分分析,最高和最低被除去,其余被加入以创建总分。

我的代码在第31行打印错误消息,说类型错误不可疑,并假设它会对所有其他列表说这个,请帮我调试我的代码,生成一个工作解决方案让用户输入5对6对夫妇得分然后删除最高和最低,并在文本文件的列表中显示所有。

使用下面给出的()建议时会出现以下错误消息: Traceback(最近一次调用最后一次):   文件“C:/ Users / Samuel / AppData / Local / Programs / Python / Python36-32 / text saving scores.py”,第32行,in     listA = list(coupleA_judge1,coupleA_judge2,coupleA_judge3,coupleA_judge4,coupleA_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))

2 个答案:

答案 0 :(得分:-1)

你肯定需要使用一些循环,所以没有那么多代码,但我认为问题是在第31行,当你应该使用list()时,你将list方法称为list []。我不在我的电脑上,所以这不可能,但它看起来像我

答案 1 :(得分:-1)

我认为Dan提出的list()想法可能是一个好的开始。你在这里的另一个选择是对列表进行排序,然后绘制列表的子字符串(子字符串包含小于最高值和大于最低值的值),而不是删除max和min,尽管删除内存效率会更高我认为最大和最小。