Python Base---recursion

Source: Internet
Author: User

1 #binary lookup algorithms must process an ordered list2L = [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]3 #print (L.index ())4 5 #Code Implementation6 defFind (L,aim,start = 0,end =None):7end = Len (l)ifEnd isNoneElseEnd8Mid_index = (end-start)//2 +Start9     ifStart <=End:Ten         ifL[mid_index] <aim: One             returnFind (L,aim,start =mid_index+1,end=end) A         elifL[mid_index] >aim: -             returnFind (L, aim, Start=start, end=mid_index-1) -         Else: the             returnMid_index -     Else: -         return 'This value is not found' -  +ret= Find (l,66) - Print(ret)
1 #Netherfield retracement2 deffib (n):3     ifn = = 1orn = = 2:4         return15     Else:6         returnFIB (n-1) + fib (n-2)7 8 Print(FIB (5))9 Ten deffib (n): One     ifn = = 2: A         returnThe -     Else: -A, B = fib (n-1) the         returnb,a+b - Print(FIB (5))
# factorial def FAC (N):     if n ==1:        return 1    return N*FAC (n-1)

Python Base---recursion

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.