在python中,for循环不循环实数。

问题描述 投票:0回答:1

我的程序每次输出选手的分数都是7,而不是选手的编号谁能帮我解决这个问题(程序还没有完全完成,我知道程序中还有其他错误的问题,请你只解决 "j不循环的问题",而不是其他问题)

numJudges = 7
numCompetitors = int(input("Enter number of competitors(between 3 and 16 inc)" ))


for comp in range(0,numCompetitors):
    totalC = 0

    print("input scores between 0 and 10 for each Judge")

    for j in range(0, numJudges):
        j = j+1
        scoreJ = int(input("Score for judge"))

        totalC = totalC + scoreJ

    scoreC = totalC / numJudges 
    print("Score for competitor ", j ," is", scoreC)

python
1个回答
1
投票

j 不是你的参赛者的编号--是最后一个评委的ID。

你需要输出的是 comp 在最后一行代替。

print("Score for competitor ", comp ," is", scoreC)

0
投票

你的最后一行应该是:print("Score for competitor ", comp+1 ," is", scoreC)

© www.soinside.com 2019 - 2024. All rights reserved.