我正在嘗試創建一個程序,以便將數值分數從最高到最低排列。確定等級中的關係
for i in scores:
if i[1] == max_score:
print 'rank ', ctr,'highest score: {} of {}'.format(i[1], i[0])
pass
if i[1] not in [max_score, min_score]:
ctr= ctr+1
print'rank ', ctr,'score: {} of {}'.format(i[1], i[0])
pass
if i[1] == min_score:
ctr= ctr+1
print 'rank ',ctr,'lowest score: {} of {}'.format(i[1], i[0])
文本文件包含:
john = 10
johnny=10
joseph = 9
j=9
jose = 8
q=7
然而,我的代碼的輸出是:
rank 1 highest score: 10.0 of john
rank 1 highest score: 10.0 of johnny
rank 2 score: 9.0 of joseph
rank 3 score: 9.0 of j
rank 4 score: 8.0 of jose
rank 5 lowest score: 7.0 of q
在行'ctr = ctr + 1'中,您只需增加每個位置。你從不檢查分數是否與之前的分數相符。 –
感謝您的幫助,你能給我一個指導如何檢查以前的分數,如果你不介意?非常感謝你 –