Question 2: Next Fibonacci Object
Question 2: Next Fibonacci Object
Implement the next method of the Fib class. For this class, the value attribute is a Fibonacci number. The next method returns a Fib instance whose value is the next Fibonacci number. The next method should take only constant time.
Hint: Assign value and previous attributes within next.
class Fib(): """A Fibonacci number. >>> start = Fib() >>> start 0 >>> start.next() 1 >>> start.next().next() 1 >>> start.next().next().next() 2 >>> start.next().next().next().next() 3 >>> start.next().next().next().next().next() 5 >>> start.next().next().next().next().next().next() 8 """ def __init__(self): self.value = 0 def next(self): "*** YOUR CODE HERE ***" def __repr__(self): return str(self.value)