Challenge: Stateful Running Average Generator
Compito
Swipe to start coding
Create a generator function running_average() that maintains a running average of numbers sent to it using the send() method. Each time a new number is sent, the generator should yield the updated average.
- Update the running total and count each time a new value is sent.
- Compute the average as a float after each new value is received.
- Yield the current average after processing each new value.
Soluzione
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 4
single
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Awesome!
Completion rate improved to 6.67
Challenge: Stateful Running Average Generator
Scorri per mostrare il menu
Compito
Swipe to start coding
Create a generator function running_average() that maintains a running average of numbers sent to it using the send() method. Each time a new number is sent, the generator should yield the updated average.
- Update the running total and count each time a new value is sent.
- Compute the average as a float after each new value is received.
- Yield the current average after processing each new value.
Soluzione
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 4
single