1
myarray = [1,20,30,44,5,57,8]

def maxProduct(array):
    maxprod = array[0]
    for i in range(len(array)):
        for j in range(i + 1,len(array)):
            if array[i] * array[j] > maxprod:
                maxprod = array[i] * array[j]
                pairs = str(array[i]) + "," + str(array[j])
    
    print(pairs) # **Expected an error but got the output -> 44,57**

maxProduct(myarray)

The pairs variable is being printed outside the if block. How is it printing without error?

Asif_102
  • 53
  • 5

0 Answers0