Python recursive for cycle Fibonacci sequence

Time:2019-8-10
# Recursion
def myAdd(a, b):
    c = a + b
    print(c)
    if c > 100:
        return
    Return myAdd (a + 1, c) # Maximum recursive depth is 1000
myAdd(2, 3)

# Functional Ibid Recursion
a = 2
b = 3
for i in range(1000):
    c = a + b
    print(c)
    a += 1
    b = c

def myFibo(a, b):
    c = a + b
    print(c)
    if c > 500:
        return
    return myFibo(b, c)

myFibo(0, 1)

a = 0
b = 1
for i in range(1000):
    c = a + b
    print(c)
    a = b
    b = c
    if c > 500:
        break

 

Recommended Today

Manjaro uses SS method (requires nodejs environment)

Just installed manjaro, need to installshadowsocks-qt5+Proxy SwitchyOmega, but the latest Chrome has long blocked the installation of non Google store CRX channels. Here is my solution, which is troublesome but usable. If you are familiar with NPM commands in nodejs, you won’t find it troublesome, because nodejs is used for compilation. Preparation environment: A VPS […]