对于两个耦合序列的给定递归关系,无法解压缩不可迭代的int对象吗?

问题描述 投票:0回答:1

我已经创建了两个耦合序列的递归关系代码,但是由于某种原因,我遇到了错误

代码:

import math

for x,y in range(1,3):
    def Function_X_Y(x,y):
        x_val = (-5*x*(n-2)) + (2*y*(n-1))
        y_val = (3*y*(n-2)) - (4*x*(n-1)) + (4*y*(n-1)) 
        return(x_val, y_val)

def coupled_sequence(n):
    return Function_X_Y(x,y)

print(coupled_sequence(0))
print(coupled_sequence(1))
print(coupled_sequence(5))

#Expected output: print(coupled_sequence(0))
#>>> (1, 1)

#print(coupled_sequence(1))
#>>> (2, 2)

#print(coupled_sequence(5))
#>>> (246, 322)

错误

----> 5 for x,y in range(1,3):
      6     def Function_X_Y(x,y):
      7         x_val = (-5*x*(n-2)) + (2*y*(n-1))

TypeError: cannot unpack non-iterable int object 

[for循环,我尝试了不同的方法来迭代给定的函数,但无法获得预期的输出

python python-3.x recurrence
1个回答
0
投票

Range,因为它正在使用,所以每次迭代只会返回一个整数,因此您不能以这种方式获取多个值。根据您的用例,您可以在自己的内部创建另一个循环,请参见此question

© www.soinside.com 2019 - 2024. All rights reserved.