Sectionย 1. Chapterย 4
single
Challenge: Fibonacci Iterator
Swipe to show menu
Task
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.
Solution
Everything was clear?
Thanks for your feedback!
Sectionย 1. Chapterย 4
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat