python basis - function recursively

# Recursive nature: 
# 1. You must have a clear end condition 
# 2 every time you enter a deeper level when a recursive, recursive problem size should be reduced compared to the previous 
# 3 recursive efficiency is not high, too recursion level multi cause stack overflow 
DEF Calc (n-):
     Print (n-)
     IF int (n-/ 2) == 0:
         # // rounding 
        # / supplier take 
        # % remainder 
        # where int is rounded, less than 1 List when rounding the result is 0 
        return n- # return return results 

return Calc (int (n-/ 2)) # perform calc (int (n / 2) ) ----> n-return waiting return results ---> last return The final result RES = Calc (10 ) Print (RES)

 

Guess you like

Origin www.cnblogs.com/tangcode/p/10984011.html