我需要为用户编写一个程序,以便能够输入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")
print(cartesianProduct([firstList], [secondList]))
cartesianProduct
是在input
之前定义的未使用变量。该函数称为CartesianProduct
。
此外,Python按照约定使用snake_case,因此函数名称应为cartesian_product
。