四、数据类型_4.(4).tuple - 例题

例题

# 斐波那契数列
def f(N) :
    m,n = 0,1
    t = 0

    while t < N :
        print(n,end=',')
        m,n = n,n+m
        t += 1
f(5)

1,1,2,3,5,
# 1.
def f1(N) :
    m,n = 0,1
    t = 0

    while t < N :
        yield n
        m,n = n,n+m
        t += 1
res = f1(5)
print(list(res))

N = int(input('请输入需要获取的位数:'))
for i in f1(N) :
    print(i,end=',')

[1, 1, 2, 3, 5]
请输入需要获取的位数:12
1,1,2,3,5,8,13,21,34,55,89,144,
# 2.
def f2() :
    m,n = 0,1

    while True :
        yield n
        m,n = n,n+m

N = int(input('请输入需要获取的位数:'))
res = f2()
for i in range(N) :
    print(next(res),end=',')

请输入需要获取的位数:12
1,1,2,3,5,8,13,21,34,55,89,144,
上一篇:Codeforces Round #750 (Div.2) A~F1题解


下一篇:[Guava官方文档翻译] 1.Guava简介 (Introduction)