苦苦于在列表中添加数字(不支持的操作数类型)

时间:2016-06-08 21:12:37

标签: python list

尝试让这个程序适用于学校项目,但是在代码的第26行,我得到了'int'和'str'的不支持的操作数类型错误。任何帮助,将不胜感激。这是代码:

final = False
while final == False:

    while True:
            try:
                eventName = str(input("What is the event's name? "))
                numberJudges = int(input("How many judges are there? "))
                competitorName = str(input("What is the competitor's name? "))
                judgeScores = input("Please enter the judges scores with a space between each one. ")
                break
            except ValueError:
                print("That is not a valid name or number(s)") 
    finalJudges = numberJudges - 2

    def judgeScoreListFunction(judgeScores):
        judgeScoreList = judgeScores.split()
        return judgeScoreList

    def cleanJudgeScoresFunction(judgeScoreList):
        judgeScoreList.remove(max(judgeScoreList))
        judgeScoreList.remove(min(judgeScoreList))
        finalJudgeScores = judgeScoreList 
        return finalJudgeScores

    def cleanScoreFunction(finalJudgeScores, finalJudges):
        cleanedScore = sum(finalJudgeScores)
        finalScore = cleanedScore / finalJudges
        format(finalScore, '.2f')
        return finalScore

    judgeScoreList = judgeScoreListFunction(judgeScores)
    finalJudgeScores = cleanJudgeScoresFunction(judgeScoreList)
    finalScore = cleanScoreFunction(finalJudgeScores, finalJudges)

    if competitorName == "Finish":
        final = True

1 个答案:

答案 0 :(得分:3)

而不是:

judgeScoreList = [int(X) for X in judgeScores.split()]

你想:

// Traversal in forward direction only:
function smaller(array, distance) {
    var length = array.length,
        result = new Array(length).fill(null),
        stack = [];
    
    // Forward pass:
    for (var i = 0, j = distance; j < length; ++i, ++j) {
      while (stack.length > 0 && array[j] < array[stack[stack.length - 1]]) {
        result[stack.pop()] = array[j];
      }
      stack.push(i);
    }
    return result;
}

console.log(smaller([0, 2, 1], 0)); // [null, 1, null]
console.log(smaller([5, 2, 1, 7, 6, 0], 1)); // [1, 0, 0, 0, null, null]

我还建议摆脱所有这些小功能。