Challenge 1: Average of Numbers
Given an array of numbers, compute the average of all the numbers recursively.
We'll cover the following
Problem Statement
Implement a function that computes the average of all the numbers in an array.
If we have numbers where each number is denoted by , the average is the of the numbers divided by or;
Try solving this problem recursively.
Input
- A
testVariable
containing an array of numbers. - The
currentIndex
of the array.
Output
Average of the numbers in the input array.
Sample Input
testVariable = [10, 2, 3, 4, 8, 0]
currentIndex = 0
Sample Output
4.5
Try it Yourself
Try to attempt this challenge by yourself before moving on to the solution. Good luck!
def average(testVariable, currentIndex = 0) :# Write your code herereturn None
Let’s have a look at the solution review of this problem.