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

Implementation of PHP Facades

Example <?php class RealRoute{ public function get(){ Echo’Get me’; } } class Facade{ public static $resolvedInstance; public static $app; public static function __callStatic($method,$args){ $instance = static::getFacadeRoot(); if(!$instance){ throw new RuntimeException(‘A facade root has not been set.’); } return $instance->$method(…$args); } // Get the Facade root object public static function getFacadeRoot() { return static::resolveFacadeInstance(static::getFacadeAccessor()); } protected […]