Files
30-seconds-of-code/snippets/average.md
Isabelle Viktoria Maciohsek a2cd6db3b0 Update snippet descriptions
2020-11-02 19:27:07 +02:00

19 lines
292 B
Markdown

---
title: average
tags: math,list,beginner
---
Calculates the average of two or more numbers.
- Use `sum()` to sum all of the `args` provided, divide by `len()`.
```py
def average(*args):
return sum(args, 0.0) / len(args)
```
```py
average(*[1, 2, 3]) # 2.0
average(1, 2, 3) # 2.0
```