Introduction
In Python, calculating the average of a set of numbers is a common task. In this challenge, you will be asked to write a function that takes in two or more numbers and returns their average.
In Python, calculating the average of a set of numbers is a common task. In this challenge, you will be asked to write a function that takes in two or more numbers and returns their average.
Write a function called average
that takes in two or more numbers and returns their average. Your function should follow these guidelines:
sum()
to sum all of the args
provided, divide by len()
.def average(*args):
return sum(args, 0.0) / len(args)
average(*[1, 2, 3]) ## 2.0
average(1, 2, 3) ## 2.0
In this challenge, you have written a function that calculates the average of two or more numbers. You have used the sum()
function to add up all of the numbers and then divided by the number of arguments using len()
. This is a useful function to have in your Python toolbox for future projects.