avatar Bite 66. Calculate the running average of a sequence

Write a function that takes a sequence of items and returns the running average, so for example this:

running_mean([1, 2, 3])


[1, 1.5, 2]

You can assume all items are numeric so no type casting is needed.

Round the mean values to 2 decimals (4.33333 -> 4.33). See the tests for more info.

Bonus: use a function of itertools + make it a generator, but this is not required to get this working.

Login and get coding
go back Beginner level
Bitecoin 2X

569 out of 577 users completed this Bite.
Will you be Pythonista #570 to crack this Bite?
Resolution time: ~36 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 3.5 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help