Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Create a Countdown Iterator | Understanding Iterators
Efficient Data Handling in Python

bookChallenge: Create a Countdown Iterator

Taak

Swipe to start coding

Create a class Countdown that acts as an iterator, yielding numbers from a specified starting value down to zero. The iteration should stop after yielding zero, and any further calls should raise StopIteration.

  • The Countdown class must implement the iterator protocol by defining both __iter__ and __next__ methods.
  • The __next__ method should yield the current value, then decrement it by one each time it is called.
  • Once the value goes below zero, __next__ must raise StopIteration.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 3
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

close

bookChallenge: Create a Countdown Iterator

Veeg om het menu te tonen

Taak

Swipe to start coding

Create a class Countdown that acts as an iterator, yielding numbers from a specified starting value down to zero. The iteration should stop after yielding zero, and any further calls should raise StopIteration.

  • The Countdown class must implement the iterator protocol by defining both __iter__ and __next__ methods.
  • The __next__ method should yield the current value, then decrement it by one each time it is called.
  • Once the value goes below zero, __next__ must raise StopIteration.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 3
single

single

some-alt