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.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 6.67
Challenge: Fibonacci Iterator
Sveip for å vise menyen
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.
Løsning
Takk for tilbakemeldingene dine!
single