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)