好的。这是我第一次问一个问题,所以请不要太复杂。我正在尝试设置我的Python程序,以便它包含三个不同类别的分数列表:测验,程序和测试,并将它们放入列表中。我的代码如下所示:如何向索引添加索引
QUIZ_GRADES = int(input("How many quiz grades? "))
PROGRAM_GRADES = int(input("How many program grades? "))
TESTS = int(input("How many tests? "))
def main():
globalConstantList = [QUIZ_GRADES, PROGRAM_GRADES, TESTS]
scoreList = [0] * (QUIZ_GRADES + PROGRAM_GRADES + TESTS)
returnedScoresList = getGrades(globalConstantList,scoreList)
#totalList(totalScore[scores])
#userOutput()
print(returnedScoresList)
def getGrades(globalConstantList,scoreList):
for eachScore in globalConstantList:
#totalScoreList = 0.0
index = 0
for index in range(QUIZ_GRADES):
print("What is the score for quiz", index + 1)
scoreList[index] = float(input())
for index in range(PROGRAM_GRADES):
print("What is the score for program", index + 1)
scoreList[index] = float(input())
for index in range(TESTS):
print("What is the score for test", index + 1)
scoreList[index] = float(input())
return scoreList
main()
(很抱歉,如果一切都没有被放置在代码样品 - FYI语法是正确的。)
这里是我的问题:每次我跑我的代码,它会将我所有的QUIZ_GRADES
值添加到从QUIZ_GRADES
for循环的scoreList[]
列表中,但随后当我运行PROGRAM_GRADES
for-loop时,它将取出我的原始值(从QUIZ_GRADES
)并放入PROGRAM_GRADES
)。例如,如果我为我的测验分数输入99,98和97,为我的程序分数输入96,它将删除最初的99并放置在96中。是否有一种方法可以填写整个scoreList
而不会擦除任何我的价值观?由于
scoreList.append – enderland