Python学习笔记------函数递归的特征

# ***********************************函数递归的特征***********************************
# 1.必须有一个明确的结束条件
# 递归的效率并不是很高


list = ['a', 'b', 'c', 'd']
def methon(list):
    if len(list) == 0:
        return '根本没人知道'
    person = list.pop(0)
    if person == 'c':
        return '%s说:我知道,大明湖北门对面就是' % person

    print('hi, %s,你知道火车站在哪儿么'%person)
    print('%s回答到,我不知道,我帮你问问%s'%(person,list))
    res = methon(list)
    # 问路的返回结果,倒序返回,因为有个res一直在等待结果的返回
    print('%s问的结果是: %s' % (person, res))
    return res

methon(list)

猜你喜欢

转载自blog.csdn.net/weixin_39180334/article/details/81045642