+1 vote
can you give an example?
Apr 2, 2019 in Python 719 views

## 2 answers to this question.

0 votes
```def Binary_search (array , element):

first = 0

last = n-1

found = False

while first<=last and not found:

mid = (first+last)//2

if element > array[mid] :

first = mid + 1

elif array[mid] == element :

found = True

else :

last = mid - 1

if found == True:

print ('ELEMENT IS FOUND At LOCATION : ' ,mid)

else:

print ('ELEMENT IS NOT FOUND ')

import numpy

n = int (input ('ENTER ARRAY SIZE \n'))

array = numpy.ndarray(shape = (n) , dtype = int)

print ('ENTER ARRAY ELEMENTS IN INCREASING ORDER |_ONLY_| ')

for i in range (n):

array[i] = int (input ())

print ('ARRAY ELEMENTS ARE :\n\t=',array)

element = int (input ('ENTER ELEMENT TO SEARCH IN ARRAY \n'))

Binary_search(array,element)

```
answered Jul 10, 2020 by _amrut_
0 votes

def Binary_search (array , element):

first = 0

last = n-1

found = False

while first<=last and not found:

mid = (first+last)//2

if element > array[mid] :

first = mid + 1

elif array[mid] == element :

found = True

else :

last = mid - 1

if found == True:

print ('ELEMENT IS FOUND At LOCATION : ' ,mid)

else:

print ('ELEMENT IS NOT FOUND ')

import numpy

n = int (input ('ENTER ARRAY SIZE \n'))

array = numpy.ndarray(shape = (n) , dtype = int)

print ('ENTER ARRAY ELEMENTS IN INCREASING ORDER |_ONLY_| ')

for i in range (n):

array[i] = int (input ())

print ('ARRAY ELEMENTS ARE :\n\t=',array)

element = int (input ('ENTER ELEMENT TO SEARCH IN ARRAY \n'))

Binary_search(array,element)

answered Jul 10, 2020 by anonymous
• 240 points

0 votes
1 answer

## I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

+3 votes
7 answers

## How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

+2 votes
2 answers

## How can I create a new file in Python?

You can try the below code which ...READ MORE

0 votes
1 answer

## How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

0 votes
2 answers

## How do I copy a file in python?

copy a file in python  from shutil ...READ MORE

0 votes
1 answer

## How do I copy a file in python?

Use the shutil module. copyfile(src, dst) Copy the contents ...READ MORE

0 votes
2 answers

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote
2 answers

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

0 votes
1 answer

## how do i use the enumerate function inside a list?

Enumerate() method adds a counter to an ...READ MORE

+5 votes
6 answers

## Lowercase in Python

You can simply the built-in function in ...READ MORE