如何提取两个以上因素?

时间:2018-07-21 15:07:06

标签: python list

这是下面的python代码,用于查找整数的因子对。如果我只需要查找三胞胎或四胞胎而不是成对,该怎么办。我希望用户在他/她想要的子列表中定义因子的数量。有关准确的信息,请留意评论。

N = []
J = []
F = []
Z = []
S = []
num = input("Enter no. of elements in list")
print ('Enter numbers')
prod = 1
for i in range(int(num)):
    n = input("num :")
    N.append(int(n))
for x in N:
    prod = prod*x
print (prod)
k = input("Enter no. of splits:")
for o in range(1,prod+1):
    if prod%o == 0:
        J.append(o)
        F.append(o) ##I want as many as lists as user defines.
print (J)

Z = [[a, b] for a in J for b in F if a*b == prod] ##**here I want more variables instead of just a and b but according to users definition**
print (Z)

0 个答案:

没有答案