Created
August 25, 2024 16:55
-
-
Save Momellouky/7e52738403cfdf6758701acdafb1840b to your computer and use it in GitHub Desktop.
Linear Search on an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def linear_search(data, param) -> bool : | |
for el in data : | |
if el == param : # We found it | |
return True | |
return False | |
if __name__ == '__main__' : | |
data = [ 7, 10, 3, 1, 66, 6 ] | |
param = 1 # The integer we are looking for in the array | |
try : | |
number = linear_search(data) | |
print(f"Number {number} found in the data array") | |
except : | |
print(f"Number {param} not found in the array") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment