Challenge: Stateful Running Average Generator
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.
Lösning
Tack för dina kommentarer!
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Can you explain this in simpler terms?
What are the main benefits or drawbacks?
Can you give me a real-world example?
Awesome!
Completion rate improved to 6.67
Challenge: Stateful Running Average Generator
Svep för att visa menyn
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.
Lösning
Tack för dina kommentarer!
single