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

bookChallenge: Stateful Running Average Generator

Tarefa

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.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 4
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain this in simpler terms?

What are the main benefits or drawbacks?

Can you give me a real-world example?

close

bookChallenge: Stateful Running Average Generator

Deslize para mostrar o menu

Tarefa

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.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 4
single

single

some-alt