Challenge: 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.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Can you explain that in simpler terms?
What are the main benefits of this approach?
Are there any common mistakes to avoid with this?
Awesome!
Completion rate improved to 6.67
Challenge: 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.
Рішення
Дякуємо за ваш відгук!
single