题目描述
100个人围成一圈,每个人有一个编码,编号从1开始到100。他们从1开始依次报数,报到为M的人自动退出圈圈,然后下一个人接着从1开始报数,直到剩余的人数小于M。请问最后剩余的人在原先的编号为多少? 例如输入M=3时,输出为: “58,91” ,输入M=4时,输出为: “34,45,97”。
def deletegame(M):
num = list(range(1,101))
index = 1
while(len(num)>= M):
length = len(num)
i= 0
for k in range(length):
if index == M:
print("%s即将下线"%num[i])
del(num[i])
index = 1
else:
i += 1
index += 1
print("moving")
print(num)
if __name__ == '__main__':
str = input("input a int number between 2-100 ")
try:
while (not(str.isdigit()) or int(str)>100 or int(str)<2):
str = input("input a int number between 2-100 ")
M = int(str)
deletegame(M)
except ValueError:
print("please input a number")