python-遞迴函式

來源:互聯網
上載者:User

標籤:none   print   es2017   sed   ges   問題:   百度   pen   堆排   

預設的遞迴最大限度1000
不要修改預設的遞迴最大限度
往往遞迴都是和迴圈掛在一起的
人理解迴圈,神理解遞迴
演算法
認識遞迴
遞迴函式怎麼讀?
例題

演算法:一種計算的方法
典型問題:冒泡排序,快速排序,堆排序
二分尋找法:尋找下面例題中的58
二分尋找
def find_2(l,aim,start=0,end=None):    if end == None:end = len(l) -1    if end >= start:        mid = (end - start) // 2 + start        if l[mid] > aim:            ret = find_2(l,aim,start,mid-1)            return ret        elif l[mid] < aim :            ret = find_2(l,aim,mid+1,end)            return ret        else:return aim,mid    else :        print(‘尋找不到內容‘)find_2(l,58)

階乘的計算
什麼叫階乘:7*6*5*4*3*2*1
階乘的計算
斐波那契數列
斐波

 

 三級菜單
三級菜單
menu = {    ‘北京‘: {        ‘海澱‘: {            ‘五道口‘: {                ‘soho‘: {},                ‘網易‘: {},                ‘google‘: {}            },            ‘中關村‘: {                ‘愛奇藝‘: {},                ‘汽車之家‘: {},                ‘youku‘: {},            },            ‘上地‘: {                ‘百度‘: {},            },        },        ‘昌平‘: {            ‘沙河‘: {                ‘老男孩‘: {},                ‘北航‘: {},            },            ‘天通苑‘: {},            ‘回龍觀‘: {},        },        ‘朝陽‘: {},        ‘東城‘: {},    },    ‘上海‘: {        ‘閔行‘: {            "人民廣場": {                ‘炸雞店‘: {}            }        },        ‘閘北‘: {            ‘火車戰‘: {                ‘攜程‘: {}            }        },        ‘浦東‘: {},    },    ‘山東‘: {},}def menu_3(menu):    while True:        for key in menu:            print(key)        choice = input(‘choice:‘)        if choice == ‘q‘ or choice == ‘b‘:            return choice        if choice in menu and menu[choice]:            borq = menu_3(menu[choice])            if borq == ‘q‘: return ‘q‘menu_3(menu)


 

 

 
 

 

python-遞迴函式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.