AILearn
Problems

3. Array Mean Calculator

Easy

Write a function calculate_mean(arr) that calculates the mean (average) of an array without using np.mean().

Example:

Input: arr = [2, 4, 6, 8, 10]

Output: 6.0

Constraints:

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

    Test Case 1
    Input: [2, 4, 6, 8, 10]
    Expected: 6.0
    Test Case 2
    Input: [1, 2, 3]
    Expected: 2.0
    Test Case 3
    Input: [10, 20, 30, 40]
    Expected: 25.0
    + 2 hidden test cases
    Python 3
    Loading editor...
    Console Output
    Click "Run" to test your code or "Submit" to submit your solution.