zoukankan      html  css  js  c++  java
  • Day5:Variable and recursive function

    """

    NAME = 'alex'          # global variable be capital

    def change_name():

         global name       # if no declaring the global name can also change the clglobal variable bu using the method of list:such as .appened()

         name = 'handsome' # local variable,be lower-case can have the same name,the difference between "c" program

         print('abcd',name)

         

    change_name()

    print(name)

    # ***********Function nest fuction*********

    NAME = 'alex'

    def zxver():

        name = 'zxver'

        print(name)

        def liu():

            name = 'liu'

            print(name)

            def linda():

                name = 'linda'

                print(name)

            print(name)

            linda()

        liu()

        print(name)

    zxver()

    # ********import easily be wrong

    AssertionErrorname = 'alex'

    def zxver():

        name = 'zxver'

        def liu():

            #1:global name

            nonlocal name 

            # 2:last stage's variable

            name = 'liu'

        liu()

        print(name)

        # ********1:print:zxver************

        # ********2:print:liu************

    print(name)

    zxver()

    print(name)

    # be careful: before the quote ,every function must be defined or will report wrong

    # ********recursion***************

    def calc(n):

        print(n)

        if (int(n/2) == 0):

           return(n)

        res = calc(int(n / 2))

        return(res)

    calc(10)

    """

    # *********defect:low efficiency*******

    import time

    person_list = ['alex','keyu','zxver','linda']

    def askway(person_list):

        print('-'*60)

        if len(person_list) == 0:

            return 'no one knows the way'

        person = person_list.pop(0)

        if person == 'zxver':

            return '%ssaid the way is turn left'%person

        print('do you know the way of the hall')

        print('%ssaid I do not know the way but i can ask %s'%(person,person_list))

        time.sleep(5)

        res = askway(person_list)

        print('%s the result is :%res'%(person,res))

        return res

        

    res = askway(person_list)

    print(res)

  • 相关阅读:
    Circular dependency issuse on cocoapods version(0.36.0) 全然解决方式(非降版本号)
    Android Studio经常使用配置及使用技巧(二)
    poj 2195 Going Home(最小费最大流)
    OpenFace库(Tadas Baltrusaitis)中基于Haar Cascade Classifiers进行人脸检測的測试代码
    Divisibility by Eight
    hdu 5055(坑)
    微服务(Microservices)
    mysql 运行计划explain具体解释
    URAL 题目1297. Palindrome(后缀数组+RMQ求最长回文子串)
    Windows下将nginx安装为服务运行
  • 原文地址:https://www.cnblogs.com/zxver/p/11974214.html
Copyright © 2011-2022 走看看