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

bookChallenge: Create a Countdown Iterator

Tarea

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.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 3
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

close

bookChallenge: Create a Countdown Iterator

Desliza para mostrar el menú

Tarea

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.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 3
single

single

some-alt