zoukankan      html  css  js  c++  java
  • day04_04 斐波那契

    __author__ = "Alex Li"
    
    '''
    def fib(max): #10
        n, a, b = 0, 0, 1
        while n < max: #n<10
            #print(b)
            # 把fib函数变成generator,只需要把print(b)改为yield b就可以了
            yield b
            a, b = b, a + b
            #a = b          a =1, b=2--> a=b --> a=2,
            # b = a +b      b = 2+2 = 4
            n = n + 1
            
    f= fib(100)
    print("---------dddd")
    print(f.__next__())
    print("======")
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    print(f.__next__())
    
    
    print("====start loop======")
    for i in f:
       print(i)
    '''
    
    '''
    def fib(max): #10
        n, a, b = 0, 0, 1
        while n < max: #n<10
            #print(b)
            # 把fib函数变成generator,只需要把print(b)改为yield b就可以了
            yield b
            a, b = b, a + b
            #a = b          a =1, b=2--> a=b --> a=2,
            # b = a +b      b = 2+2 = 4
            n = n + 1
        return '----no more value----'
    
    
    f = fib(10)
    
    # print("---------dddd")
    # print(f.__next__())
    # print("======")
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    # print(f.__next__())
    
    print("====start loop======")
    #for i in f:
    #    print(i)
    '''
    
    #异常处理
    def fib(max): #10
        n, a, b = 0, 0, 1
        while n < max: #n<10
            #print(b)
            # 把fib函数变成generator,只需要把print(b)改为yield b就可以了
            yield b
            a, b = b, a + b
            #a = b          a =1, b=2--> a=b --> a=2,
            # b = a +b      b = 2+2 = 4
            n = n + 1
        return '----no more value----'
    
    
    f = fib(10)
    while True:
        try:
            x = next(f)
            print('f:', x)
        except StopIteration as e:
            print('Generator return value:', e.value)   # return '----no more value----'
            break
    
    print("====start loop======")
    #for i in f:
    #    print(i)
    
  • 相关阅读:
    2021秋 数分B1笔记
    android逆向奇技淫巧二十三:自己写app调用x音关键so(未完待续)(八)
    android逆向奇技淫巧二十二:ida栈回溯加密算法跟踪(未完待续)(七)
    http tcp websocket
    location.reload
    event.preventDefault
    document.querySelector
    造成播放端卡顿的原因
    引入外部组件 Vue.use()和Vue.component()
    Interpolation
  • 原文地址:https://www.cnblogs.com/netflix/p/14854401.html
Copyright © 2011-2022 走看看