Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Stateful Running Average Generator | Advanced Generator Patterns and Applications
Quizzes & Challenges
Quizzes
Challenges
/
Efficient Data Handling in Python

bookChallenge: Stateful Running Average Generator

Tâche

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.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 4
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: Stateful Running Average Generator

Glissez pour afficher le menu

Tâche

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.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 4
single

single

some-alt