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.
Solution
Merci pour vos commentaires !
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Awesome!
Completion rate improved to 6.67
Challenge: Fibonacci Iterator
Glissez pour afficher le menu
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
Merci pour vos commentaires !
single