Python3 recursive function, python3 Recursive Function
1 # def fat (n): 2 # result = 1 3 # for I in range (2, n + 1 ): 4 # result = result * I 5 # return result 6 # print (fat (5) 7 #8 #9 # def digui (x ): 10 # if x = # return 112 # return x * digui (x-1) 13 # print (digui (5 )) 14 #15 # ''' 16 # recursive Summary: 17 #1. internally, it calls itself 18 #2. there is an end condition 19 #3. but any recursion that can be written can be done in a loop of 20 #4. low recursion Efficiency 21 # ''' 22 #23 #24 ## recursive version Fibonacci Series 25 #0 1 1 2 3 5 8 13 21... 26 # def feibonaqidigui (a): 27 # if a = 0 or a = # return a29 # return feibonaqidigui (A-1) + feibonaqidigui (A-2) 30 # print (feibonaqidigui (8) 31 #32 # ''' 33 # recursive features: 34 #1. there must be a clear ending condition 35 #2. each time you enter a deeper layer of recursion, the problem scale is reduced by 36 #3 compared to the previous recursion. inefficient, too many recursive layers will cause stack overflow 37 #'''