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

bookChallenge: Fibonacci Iterator

Завдання

Swipe to start coding

Create a class FibonacciIterator that produces Fibonacci numbers up to a given maximum value. The iterator should begin with 0 and continue yielding the next Fibonacci number on each iteration, stopping when the next number would exceed the specified maximum. The class must define both __iter__ and __next__ methods. Each call to __next__ should return the current Fibonacci number and advance to the next one. When the next number would be greater than max_value, the iterator should raise StopIteration.

Рішення

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

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

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

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

single

Запитати АІ

expand

Запитати АІ

ChatGPT

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

Suggested prompts:

Can you explain that in simpler terms?

What are the main benefits of this approach?

Are there any common mistakes to avoid with this?

close

bookChallenge: Fibonacci Iterator

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

Завдання

Swipe to start coding

Create a class FibonacciIterator that produces Fibonacci numbers up to a given maximum value. The iterator should begin with 0 and continue yielding the next Fibonacci number on each iteration, stopping when the next number would exceed the specified maximum. The class must define both __iter__ and __next__ methods. Each call to __next__ should return the current Fibonacci number and advance to the next one. When the next number would be greater than max_value, the iterator should raise StopIteration.

Рішення

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

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

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

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

single

some-alt