我是 Python 语言的新手,我遇到了这个问题,下面的代码没有返回预期值:
def rabbits(n):
first = 1
second = 1
if n == 1 or n == 2:
return 1
while n > 2:
first, second = second, first + second
n -= 1
if n > 5:
die1 = 1
die2 = 1
if n == 6 or n == 7:
return second - 1
while n > 7:
die1, die2 = die2, die1 + die2
n -= 1
return second - die2
return second
我希望 rabbits(6) 会返回 7,但它会返回 8。谁能帮我在这里找到错误的东西?谢谢!