IndexError:列表索引存在范围python

时间:2017-08-16 12:56:41

标签: python

这里是我的代码,请帮我解决错误

enter image description here

1 个答案:

答案 0 :(得分:-2)

第一个条件应该更大或相等,因为当pat = 24时,程序会转到else,然后尝试访问索引24中的范围,但最后一个索引是23。

roue = range(24)
pat = int(input())
if pat >= 24:
    while pat >= 24:
        pat -= 24
else:
    while pat < 0:
        pat += 24
print(roue[pat])