Python function eight (recursive function)

Source: Internet
Author: User

One. Recursive functions

Recursive definition--call the function itself in a function

def func ():     Print (111)     return func () func ()

Max depth of recursion--997

n = 1def  func (n):    print(n)    + = 1    return  Func (N) func (1)

Modify recursive maximum depth

Import SYS Print (Sys.setrecursionlimit (100000))

Example one:

Now you ask me, Alex, how old is the teacher? I said I wouldn't tell you, but Alex is two years older than Egon.

You want to know how old Alex is, do you have to ask Egon? Egon said, I do not tell you, but I am a tournament sir two years old.

You asked Sir Wu, and the officer did not tell you, he said he was two years older than Jinxin.

Then you ask Jinxin, Jinxin told you, he is 40 ...

Did you know that at this time? How old is Alex?

def Age (N):     if n = =1        :return    elif 1 < n <= 4:          Return Age (n-1) +2print(age (4))

Find the index position of 66 in 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]

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]defFind (L,aim,start = 0,end = Len (l)-1):    #if End = = None:end = Len (l)-1    ifStart <=End:mid= (End-start)//2 +StartifL[mid] <aim:returnFind (L,aim,start=mid+1,end =end)elifL[mid] >aim:returnFind (l,aim,start=start,end=mid-1)        elifL[mid] = = Aim:returnMidElse:returnNoneret= Find (l,66)Print(ret)

Python function eight (recursive function)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.