Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Create a Countdown Iterator | Understanding Iterators
Efficient Data Handling in Python

bookChallenge: Create a Countdown Iterator

Завдання

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.

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

close

bookChallenge: Create a Countdown Iterator

Свайпніть щоб показати меню

Завдання

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.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
single

single

some-alt