I'm starting with Python
and I have a problem with the code I'm doing ...
from numpy import *
import random
def busquedaLineal(buscado, arreglo):
encontrado = 0
for i in range(len(arreglo)):
if arreglo[i] == buscado:
encontrado = 1
return encontrado
arreglo = random.sample(range(25), 10)
buscado = random.sample(range(25), 1)
print arreglo
print buscado
buscarElemento = busquedaLineal(buscado, arreglo)
print buscarElemento
if buscarElemento == 1:
print 'Si se encontro en el arreglo'
else:
print 'No se encontro en el arreglo'
the cycle for
I have changed it to use only fix or len (fix) but it does not work, for the return data (found) there is always 0 (not found) even if the random number is in the array . Does anyone have any ideas?
First line in the terminal: arrangement (random)
Second line in the terminal: number that we will look for in the array (random)
Third line in the terminal: 0 that returns from the function of búsquedaLineal
(not found)