python學習day17

來源:互聯網
上載者:User

標籤:lte   匿名函數   int   nbsp   最大   傳回值   調用   修改   電腦   

# 上周複習    #迭代器    #產生器進階    #內建函數        #55個        #帶key方法的函數:max、min、filter、map、sorted        #紅色和黃色的方法為重點    #匿名函數        #lambda 參數1,參數二:傳回值運算式        #和5個帶key的內建函數可結合使用#遞迴函式    #什麼是遞迴:在函數中自己調用自己#最大遞迴深度測試 #997# n = 0# def func():#     global n#     n+=1#     print(n)#     func()# func()# RecursionError: maximum recursion depth exceeded while calling a Python object# -->超出最大遞迴深度#修改最大遞迴深度測試#3809# import sys# sys.setrecursionlimit(100000)# n = 0# def func():#     global n#     n+=1#     print(n)#     func()# func()# 1    金鑫          40# 2    武sir      42# 3    egon          44# 4    alex       46# def age(n):#     if n == 1:#         return 40#     else:#         return age(n-1)+2## def age(4):#     if 4 == 1:#         return 40#     else:#         return 46# def age(3):#     if 3 == 1:#         return 40#     else:#         return 44# def age(2):#     if 2 == 1:#         return 40#     else:#         return 42## print(age(4))#三級菜單# menu = {#     ‘北京‘: {#         ‘海澱‘: {#             ‘五道口‘: {#                 ‘soho‘: {},#                 ‘網易‘: {},#                 ‘google‘: {}#             },#             ‘中關村‘: {#                 ‘愛奇藝‘: {},#                 ‘汽車之家‘: {},#                 ‘youku‘: {},#             },#             ‘上地‘: {#                 ‘百度‘: {},#             },#         },#         ‘昌平‘: {#             ‘沙河‘: {#                 ‘老男孩‘: {},#                 ‘北航‘: {},#             },#             ‘天通苑‘: {},#             ‘回龍觀‘: {},#         },#         ‘朝陽‘: {},#         ‘東城‘: {},#     },#     ‘上海‘: {#         ‘閔行‘: {#             "人民廣場": {#                 ‘炸雞店‘: {}#             }#         },#         ‘閘北‘: {#             ‘火車戰‘: {#                 ‘攜程‘: {}#             }#         },#         ‘浦東‘: {},#     },#     ‘山東‘: {},# }## print(menu)#演算法    #什麼是演算法:人腦複雜,電腦簡單#二分法基礎版# l = [2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55,56,66,67,69,72,76,82,83,88]## def func(l,aim):#     mid = (len(l))//2#     if l:#         if aim > l[mid]:#             func(l[mid+1:],aim)#         elif aim < l[mid]:#             func(l[:mid],aim)#         elif aim == l[mid]:#             print("bingo",mid)#     else:#         print(‘找不到‘)# func(l,66)#升級版# l = [2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55,56,66,67,69,72,76,82,83,88]# def find(l,aim,start=0,end=None):#     end =len(l) if end is None else end#     mid_index = (end - start) //2 + start#     if start<=end:#         if l[mid_index]<aim:#             return find(l,aim,start=mid_index+1,end=end)#         elif l[mid_index]>aim:#             return find(l, aim, start=start, end=mid_index-1)#         else:#             return mid_index#     else:#         return  ‘找不到這個值‘# ret=find(l,100)# print(ret)# 斐波那契  # 問第n個斐波那契數是多少# 1,1,2,3,5,8,13# def func(n):#     if n==1 or n==2:#         return 1#     else:#         return  func(n-1)+func(n-2)# ret = func(7)# print(ret)# 階乘# def func(n):#     if n == 1:#         return 1#     else:#         return n*func(n-1)# # ret = func(5)# print(ret)

 

python學習day17

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.