python学习笔记-----斐波那契数列

斐波那契数列


打印斐波那契数列前九十列,示例如下(语言不限):
1 1 2 3 5 8 13 21 34 55 ....


def fib(num):
    a, b, count = 0, 1, 1  # 0, 1
    while count <= num:
        print(b)
        a, b = b, a + b  #a=2, b=3
        count += 1


fib(90)


小插曲

集合生成式


print({i ** 2 for i in {1, 2, 3}})
print({i ** 2 for i in {1, 2, 3, 9, 12} if i % 3 == 0})


猜你喜欢

转载自blog.csdn.net/qq_41891803/article/details/81516871