递归函数

递归函数

# 传递 ; 回归
# 递归: 函数a内部直接调用函数a本身


# 真正的递归必须得要有 退出条件

# 看思路

# 递归:
# 1. 函数内部调用函数自己
# 2. 必须要有退出条件
# 3. 递归必须要有规律




def age(x):
    if x == 0:
        return 18
    x -= 1
    return age(x) + 2


res = age(6)
print(res)  # 32

'''
res = 30 
res = 28 + 2
res = 26 + 2 + 2
res = 24 + 2 + 2 + 2
res = 22 + 2 + 2 + 2 + 2
res = 20 + 2 + 2 + 2 + 2 + 2
res = 18 + 2 + 2 + 2 + 2 + 2 + 2
'''
posted @ 2020-03-29 22:08  jzm1201  阅读(92)  评论(0编辑  收藏  举报