We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8e827f9 commit 843f8f5Copy full SHA for 843f8f5
Desarrollo/20_BusquedaLineal.py
@@ -0,0 +1,22 @@
1
+import random
2
+
3
+def busqueda_lineal(lista, objetivo):
4
+ match = False
5
6
+ for elemento in lista: # O(n)
7
+ if elemento == objetivo:
8
+ match = True
9
+ break
10
11
+ return match
12
13
14
+if __name__ == '__main__':
15
+ tamano_de_lista = int(input('De que tamano sera la lista? '))
16
+ objetivo = int(input('Que numero quieres encontrar? '))
17
18
+ lista = [random.randint(0, 100) for i in range(tamano_de_lista)]
19
20
+ encontrado = busqueda_lineal(lista, objetivo)
21
+ print(lista)
22
+ print(f'El elemento {objetivo} {"esta" if encontrado else "no esta"} en la lista')
0 commit comments