递归函数就是在函数内部自己调用自己
递归的最大深度
官网是1000
实测是998
测递归深度
def foo(n): print(n) n += 1 foo(n) foo(1)
改变递归深度
import sys print(sys.setrecursionlimit(100000))
递归函数与三级菜单
menu = {'北京': {'海淀': {'五道口': {'soho': {},'网易': {},'google': {}}, '中关村': {'爱奇艺': {},'汽车之家': {},'youku': {},}, '上地': {'百度': {},},}, '昌平': {'沙河': {'老男孩': {},'北航': {},}, '天通苑': {}, '回龙观': {},}, '朝阳': {}, '东城': {},}, '上海': {'闵行': {"人民广场": {'炸鸡店': {}}}, '闸北': {'火车战': {'携程': {} }}, '浦东': {},}, '山东': {},}
def threeLM(dic): while True: for k in dic:print(k) key = input('input>>').strip() if key == 'b' or key == 'q':return key elif key in dic.keys() and dic[key]: ret = threeLM(dic[key]) if ret == 'q': return 'q' threeLM(menu)