我正在尝试返回斐波纳契数字,但是在调用start.next()。next()之后它会打印2而不是1。我该如何解决这个问题?
class Fib():
def __init__(self):
self.value = 0
def next(self):
if self.value == 0:
self.total = 1
self.previous = 0
self.value = 1
else:
print(self.previous)
self.value = self.total + self.previous
hold = self.total
self.previous, self.total = hold, self.value
return self
def __repr__(self):
return str(self.value)