Challenge: Create a Countdown Iterator
Tarefa
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
Countdownclass 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 raiseStopIteration.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 3
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 6.67
Challenge: Create a Countdown Iterator
Deslize para mostrar o menu
Tarefa
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
Countdownclass 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 raiseStopIteration.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 3
single