我写的python 约瑟夫环的程序 初学 希望大佬帮忙看看哪里错了 就是不出结果

2025-01-02 04:21:20
推荐回答(1个)
回答1:

# coding: utf-8
import time

def yoselfhuan(x, y):
result = list()
while len(x) >= 1:
for i in range(y + 1):
if i == y:
temp = x.pop(0)
result.append(temp)
print str(temp) + " is out"
else:
print x
x.append(x[0])
x.pop(0)
return result

list1 = []
n = int(input("请输入需要参加的人数:"))
for i in range(n):
if i <= n:
list1.append(i)
print list1
m = int(input("请输入到第几个人出局:"))
sequence = yoselfhuan(list1, m)
print sequence