File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
bab9_funcrecursive/test_skill Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Fibbonaci Example
2
+
1
3
def fibbonaci (x ):
2
4
if x == 0 :
3
5
return 0
Original file line number Diff line number Diff line change
1
+ # Recursive on Binnary Search
2
+
3
+ def binarySearch (mylist , item ):
4
+ if len (mylist ) == 0 :
5
+ return False
6
+ else :
7
+ midpoint = len (mylist ) // 2
8
+
9
+ if mylist [midpoint ] == item :
10
+ return True
11
+ else :
12
+ if item < mylist [midpoint ]:
13
+ return binarySearch (mylist [:midpoint ], item )
14
+ else :
15
+ return binarySearch (mylist [midpoint + 1 :], item )
16
+
17
+
18
+ if __name__ == '__main__' :
19
+ j = []
20
+ k = int (input ("Enter length of your list: " ))
21
+ for i in range (k ):
22
+ l = int (input ("element %s of your list: " % (i + 1 )))
23
+ j .append (l )
24
+ j .sort ()
25
+ print (j )
26
+
27
+ s = int (input ("Find the number : " ))
28
+ print (binarySearch (j , s ))
You can’t perform that action at this time.
0 commit comments