Update some snippets

This commit is contained in:
Angelos Chalaris
2019-08-20 10:13:54 +03:00
parent 0f405f0da9
commit a340ba4492
4 changed files with 8 additions and 29 deletions

View File

@ -1,16 +1,15 @@
---
title: average
tags: math
tags: math,list,beginner
---
:information_source: Already implemented via `statistics.mean`. `statistics.mean` takes an array as an argument whereas this function takes variadic arguments.
Returns the average of two or more numbers.
Takes the sum of all the `args` and divides it by `len(args)`. The second argument `0.0` in sum is to handle floating point division in `python3`.
Use `sum()` to sum all of the `args` provided, divide by `len(args)`.
```py
def average(*args):
return sum(args, 0.0) / len(args)
return sum(args, 0.0) / len(args)
```
```py