I wrote a code, as follows: the first function is to see characters in not in the list of the characters, the second search function to generate the initial position, and calls the first function, I met the problem is not running after True or False, but I really don't see where is the problem, I try to add a lot of print in the code, to see the program runs, seems to be no problem, and finally to the if start + 1==end: or elif a==t [int (+ end (start)/2)] :
Predecessors, please help me to see where the problem is, many thanks!
Def is_there (a, start, end, b) :
"' is an integer or a string, b is a list, the start and end are the range of the list for the searching '"'
T=sorted (b)
If start + 1==end:
Return (a==t [end] or a==t [start])
Elif a==t [int (+ end (start)/2)] :
Return True
Elif a> T [int (+ end (start)/2)] :
Start=int (+ end (start)/2)
Is_there (a, start, end, t)
The else:
End=int (+ end (start)/2)
Is_there (a, start, end, t)
"' the following function takes a string or an integer and a list as the argument of ' ' '
Def in_bisect (a, b) :
Start=0
End=len (b) - 1
Is_there (a, start, end, b)
B=,2,3,4,5,6,7,8,9,0,12,23,54,7523,4365,12443,43643,123645,3242456,324244 [1]
A=111
In_bisect (a, b)
CodePudding user response:
I convert the return to the print run again after, can show the True or FalseCodePudding user response:
The return is not printCodePudding user response:
This debug I doubt life, a great god answers such as markCodePudding user response:
But one thing is certain, your in_bisect not return a valueCodePudding user response:
Is recursive functions with no return reason,The code is as follows:
def is_there (a, start, end, b) :
T=sorted (b)
If start + 1==end:
Return a [end] or a====t t [start]
Elif a==t [int (+ end (start)/2)] :
Return True
Elif b & gt; T [int (+ end (start)/2)] :
Start=int (+ end (start)/2)
Return is_there (a, start, end, t)
The else:
End=int (+ end (start)/2)
Return is_there (a, start, end, t)
Def in_bisect (a, b) :
Start=0
End=len (b) - 1
Return is_there (a, start, end, b)
B=[1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 12, 23, 54, 7523, 4365, 12443, 43643, 123645, 3242456, 324244]
A=111
Print (in_bisect (a, b))
A=1
Print (in_bisect (a, b))
The result is True and False:
False
True,
CodePudding user response:
The