Write a FUNCTION(def) average that accepts a variable number of integer positional arguments and computes the average. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Write a FUNCTION(def) average that accepts a variable number of integer positional arguments and computes the average.

Write a FUNCTION(def) average that accepts a variable number of integer positional arguments and computes the average. If no arguments are supplied, the function should return None.

22nd Oct 2017, 4:00 PM
Бауыржан
Бауыржан - avatar
2 Answers
+ 1
def average(*args): if len(args) == 0: return None sum = 0 for arg in args: sum += arg return sum / len(args) print(average(1,2,3,4,5,6,7,8,9))
22nd Oct 2017, 4:23 PM
ChaoticDawg
ChaoticDawg - avatar
0
Thank you so much. I wanted to ask what the * sign means before args?
23rd Oct 2017, 6:11 AM
Бауыржан
Бауыржан - avatar