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

bookChallenge: Stateful Running Average Generator

Opgave

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

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 4
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

close

bookChallenge: Stateful Running Average Generator

Stryg for at vise menuen

Opgave

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

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 4
single

single

some-alt