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

## 2 answers to this question.

```def Binary_search (array , element):

first = 0

last = n-1

found = False

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:

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_

def Binary_search (array , element):

first = 0

last = n-1

found = False

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:

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

## 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

## How can I rename a file in Python?

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

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

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

## 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

## How do I copy a file in python?

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

## How do I copy a file in python?

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

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

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

+1 vote

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

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