Click4Ai

8.

Easy

Write a function array_product(arr) that returns the product of all elements in an array without using np.prod() or math.prod().

Example:

Input: arr = [1, 2, 3, 4, 5]

Output: 120

Constraints:

  • Array length: 1 <= len(arr) <= 100
  • Array values: -100 <= arr[i] <= 100
  • Test Cases

    Test Case 1
    Input: [1, 2, 3, 4, 5]
    Expected: 120
    Test Case 2
    Input: [2, 3, 7]
    Expected: 42
    Test Case 3
    Input: [5, 0, 3]
    Expected: 0
    + 2 hidden test cases