diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-11-25 20:38:03 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-11-25 20:38:03 +0200 |
commit | 4531afb7137e85dbdc45ec9147612a101568a507 (patch) | |
tree | 473fcf5b2e0ab7b1852ca7749b91231d797e2e73 /algorithms/linear_search.py | |
parent | 5df83b0e15a757b4803b66b9af6a7e5afcd1667e (diff) | |
download | cs-y13-4531afb7137e85dbdc45ec9147612a101568a507.tar.gz cs-y13-4531afb7137e85dbdc45ec9147612a101568a507.tar.bz2 cs-y13-4531afb7137e85dbdc45ec9147612a101568a507.zip |
chore: move and rename
Diffstat (limited to 'algorithms/linear_search.py')
-rw-r--r-- | algorithms/linear_search.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/algorithms/linear_search.py b/algorithms/linear_search.py new file mode 100644 index 0000000..5a54ce6 --- /dev/null +++ b/algorithms/linear_search.py @@ -0,0 +1,21 @@ +import random
+def generate_test_data(length: int, _range: tuple):
+ arr = []
+ for i in range(length):
+ arr.append(random.randint(_range[0], _range[1]))
+ return arr
+def linsearch(myList: list, valueToFind: int):
+ mindex: int = len(myList) - 1
+ index: int = 0
+ found = False
+ while not found and index <= mindex:
+ if myList[index] == valueToFind:
+ found = True
+ index += 1
+ if found: print("VALUE FOUND!!!")
+ else: print("OH NO ITEM NOT FOUND IN LIST!!")
+def main():
+ inputFind = int(input("Value to find: "))
+ linsearch(generate_test_data(10, (0, 1000)), inputFind)
+if __name__ == "__main__":
+ main()
|