n = int(input("Enter the number of elements in the array (2-200,000):"))
a = [int(x) for x in input("Enter all numbers of the sequence with only non-negative intergers not exceeding 100,000:").split()]
c = list()3
for i in range(0,n):
for j in range (1,n):
if a[i] != a[j]:
m = a[i]*a[j]
c.append(m)
else:
continue
print(max(c))
이 코드는 작동합니다. 그러나 아래 코드에서 5 번째 줄부터 최대 제품을 자동으로 계산하는 함수를 정의하고 싶습니다.최대 pairwise 제품을위한 파이썬
def MaxPairwiseProduct(n,a,c):
for i in range(0,n):
for j in range (1,n):
if a[i] != a[j]:
m = a[i]*a[j]
c.append(m)
else:
continue
Product = max(c)
return Product
n = int(input("Enter the number of elements in the array (2-200,000):"))
a = [int(x) for x in input("Enter all numbers of the sequence with only non-negative intergers not exceeding 100,000:").split()]
c = list()
MaxPairwiseProduct(n,a,c)
기능을 다시 쓰지만 작동하지 않습니다. "예상 만입 블록 IndentationError"
'else : continue'는 불필요합니다. –
중복 된 http://stackoverflow.com/questions/39329829/how-to-find-the-maximum-product-of-two-elements-in-a-list? – kennytm
@ juanpa.arrivillaga : 아니에요. 계산을 우회하고'Product'를 반환합니다. 물론 더 나은 방법이 있지만 코드를 제거하면 코드의 동작이 변경됩니다. – zondo