python学习day17

Posted wujunjie-sir

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python学习day17相关的知识,希望对你有一定的参考价值。

# 上周复习
    #迭代器
    #生成器进阶

    #内置函数
        #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的主要内容,如果未能解决你的问题,请参考以下文章

Python学习day17 任务发布

python学习day——17

python学习day17

python学习笔记-Day17(jinja2)

python学习笔记-Day17 (上节知识点补充)

python自动化学习笔记之DAY17