k =0whilelen(list1)>2:
i =0while i<len(list1):
k +=1if k ==3:# 遇3杀人
list1.remove(list1[i])
k =0else:
i +=1print(list1)
[10, 25]
defyue(x,y,z):# x是人数,y是遇y淘汰,z是幸存人数
list1 =[i for i inrange(1,x+1)]
k =0whilelen(list1)>z :
i =0while i<len(list1):
k +=1if k == y:
list1.remove(list1[i])
k =0else:
i +=1
result = list1
return result
defmove(players,step):# 移动step前的元素到列表末尾
num = step -1while num >0:
tmp = players.pop(0)
players.append(tmp)
num = num -1return players # 根据step做了元素的移动defplay(players,step,alive):#生成一个列表,从[1,...,players]
list1 =[i for i inrange(1,players+1)]#进入游戏的循环,每次数到step淘汰,step之前的元素移动到列表末尾#游戏结束的条件:列表剩余人数小于alive# 移动step前的元素到列表末尾whilelen(list1)>alive:
list1 = move(list1,step)
list1.pop(0)return list1
players_num =int(input("请输入参加游戏的人数"))
step_num =int(input("请输入淘汰的数字"))
alive_num =int(input("请输入幸存人数"))
alive_list = play(players_num,step_num,alive_num)print(alive_list)