-2

Here's the code, The main problem is to test the algorithm with the naive method and my own method.

def my_solution(numbers):
n = len(numbers)
index_1 = 1

for i in range(0,n):
    if numbers[i] > numbers[index_1]:
        index_1 = i

if index_1 == 0:
    index_2 = 1
else:
    index_2 = 0

for i in range(0,n):
    if numbers[i] != numbers[index_1] and numbers[i] >= numbers[index_2]:
        index_2 = i

sum = numbers[index_1] * numbers[index_2]
return sum

def naive_solution(numbers):
    n = len(numbers)
    max_product = 0
    for first in range(n):
        for second in range(first + 1, n):
             max_product = max(max_product,
                numbers[first] * numbers[second])

    return max_product

def testGenerator():
    pass   

def main():
    for i in range(1000):
        test = testGenerator()
        correct_answer = naive_solution(test)
        my_answer = my_solution(test)
        assert(my_answer == correct_answer)

Do I need to edit the testGenerator function? Or any other part missing for? I run the code and nothing happen.

Leoucl
  • 1
  • The `testGenerator()` function is empty. What do you expect to happen? – 9769953 Nov 28 '21 at 21:38
  • Nothing happens because you're not calling the `main()` function. That doesn't happen magically. Put the standard `if __name__ == '__main__': main()` part at the bottom of your file. That should produce some output, albeit a crash. – 9769953 Nov 28 '21 at 21:40
  • just stress testing the algorithm with number, but not sure how to do it. I guess leave it empty may not result in something? – Leoucl Nov 28 '21 at 21:40
  • Leaving the function empty will return `None`, which you feed into other functions, where you take the length of the argument. `len(None)` will fail. – 9769953 Nov 28 '21 at 21:41

1 Answers1

0

You haven't called your functions. Try calling them by using their name followed by parentheses () and any arguments that need to be entered