zoukankan      html  css  js  c++  java
  • python-递归函数

    默认的递归最大限度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)

    
    

     

     
     
  • 相关阅读:
    网络规划和布线
    网络编程
    NoSQL 非关系数据库
    OpenCV
    首页
    C++关键字
    TCP/IP 详解7 Ping指令
    TCP详解 (1)
    GRE封装解封装过程
    GRE tunnel
  • 原文地址:https://www.cnblogs.com/dwenwen/p/7818601.html
Copyright © 2011-2022 走看看