Python 斐波那契数列类问题

统计每个月兔子的总数

http://www.nowcoder.com/questionTerminal/1221ec77125d4370833fd3ad5ba72395

while True:
    try:
        month = int(input())
        count, n1, n2 = 2, 1, 1
        if month < 3:
            print(1)
        else:
            while count < month:
                nth = n1 + n2
                n1 = n2
                n2 = nth
                count += 1
            print(n2)
    except:
        break
全部评论
同时给那三个变量赋值
点赞 回复 分享
发布于 2021-05-20 09:29
可以解释下line 4 嘛~不是很明白呢!
点赞 回复 分享
发布于 2021-02-02 19:18

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务