Challenge: Working with Coroutines
Explore how to create Python coroutines that maintain a running average of numbers and build a coroutine-based log processing pipeline. Understand coroutine mechanics like sending values, stopping with None, and chaining coroutines for asynchronous workflows in this practical challenge.
We'll cover the following...
We'll cover the following...
Problem 1
In this problem, you are required to implement a coroutine running_average() that calculates the running average of numbers sent to it.
Requirements
- The coroutine should:
- Start with no numbers.
- Accept numbers using
.send(value). - After each number is sent, yield the current running average.
- If
.send()is called withNone, the coroutine should stop and return the final average.