30, python based learning - recursive function

#! / usr / bin / the env Python 
#__author: HLC 
#date: 2019/6/2 

# form 
! # 5 = 3 * 5 * 4 * 2 * 1 = 120 
# 7 = 7 * 6 * 5 * 4! *. 3 * 2 *. 1 = 5040. 

# DEF FAT (n-): 
# RET =. 1 
# for I in Range (. 1, n-+. 1): 
# RET = RET * I 
# return RET 
# Print (FAT (. 5)) # 120 

# DEF FACT (n-): 
# == n-1 IF: 
# return 1 
# n-return * FACT (-n-1) 
# Print (FACT (. 5)) 
"" " 
on recursive features: 
1, the function call itself; 
2, there is a termination condition; 
3, but those who can write recursive cycle can be solved; 
4, recursive efficiency in many cases is very low; 
5, recursive code is clear and concise than the cycle; 
"" " 

# Fibonacci of number 
# 0. 1. 5. 1 2. 8. 3 55 89 13 is 21 is 34 is  
# DEF fibo_new (n-):
# n-IF <=. 1: 
# n-return
#     return (fibo_new(n-1) + fibo_new(n-2))
# print(fibo_new(9)) # 34

  

Guess you like

Origin www.cnblogs.com/hlc-123/p/10961931.html