该函数做我想做的事情,但是当它完成时,它只是坐在那里,而不是从我称之为的地方继续,我无法弄清楚为什么。该代码是:Python函数卡住了(没有错误),但我不明白为什么
x = 9
y = 9
n = 10
ty = 1
tx = 1
while ty <= y:
while tx <= x:
vars()["p" + str(ty) + str(tx)] = 0
tx += 1
ty += 1
tx = 1
tn = 1
while tn <= n:
vars()["m" + str(tn)] = tn
tn += 1
t = x * y
tm = n
def recursion(z):
global tm
if z < n:
for x in range(n):
recursion(z + 1)
else:
if tm > 0:
tv = "m" + str(tm)
otm = eval(tv)
while eval(tv) < t - n + tm:
vars()[tv] = eval(tv) + 1
print(tv + " = " + str(eval(tv)))
vars()[tv] = otm + 1
print(tv + " = " + str(eval(tv)))
if tm > 1:
vars()["m" + str(tm - 1)] = eval("m" + str(tm - 1)) + 1
print(str("m" + str(tm - 1) + " = " + str(eval("m" + str(tm -1)))))
tm -= 1
recursion(1)
print("done")
我已经把在我希望它结束,但据我所知它不应该真正需要它的回报。
任何人都可以看到我做了什么导致它卡住?
感谢
如果它卡住了,它不会做你想要的。每次递归都需要一个基本情况,它返回一个基本值,以及一个递归部分,其中实际函数调用是在return语句中进行的。你的功能不这样做。 (return recursion(z + 1)) –
定义了哪个'n'? – dg99
@ dg99:和't',和'm1'和'm2' ...这段代码很疯狂!它看起来像是一个POCC(Python混淆代码竞赛)的入口。 – rodrigo