带有用户输入的笛卡尔积

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

我需要为用户编写一个程序,以便能够输入2-10个数字并创建笛卡尔积。这是我到目前为止的内容,但第39行说“ int”对象不可调用。我需要帮助才能完成这项工作。

print("list")


firstList=[1,4]
secondList=[2,5,6]
cartesianProduct=0

print=(input("Enter first set of numbers: "))
print=(input("Enter second set of numbers: "))

def CartesianProduct(firstList, secondList):

if len(firstList):
  return None

if len(secondList):
  return None

product=[ ]
for elementA in firstList:
 for elementB in secondList:
   product.append([elementA,elementB])

return product


print(cartesianProduct([firstList], [secondList]))    ##This is line 39

print("End Program")
python-3.x cartesian-product
1个回答
0
投票

print(cartesianProduct([firstList], [secondList]))

cartesianProduct是在input之前定义的未使用变量。该函数称为CartesianProduct

此外,Python按照约定使用snake_case,因此函数名称应为cartesian_product

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