Update some snippets
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user