summaryrefslogtreecommitdiff
path: root/_legacy/algorithms/linear_search.py
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2025-02-19 09:43:52 +0200
committerZhongheng Liu <z.liu@outlook.com.gr>2025-02-19 09:43:52 +0200
commit8834da60a01294fd509c7cebf3b129fcc378d152 (patch)
treea1c6c4bd71e95780f87d35240754c5b54d3042ae /_legacy/algorithms/linear_search.py
parent34bd7099d27656b4454015b0c410ca1713db5271 (diff)
downloadcs-y13-8834da60a01294fd509c7cebf3b129fcc378d152.tar.gz
cs-y13-8834da60a01294fd509c7cebf3b129fcc378d152.tar.bz2
cs-y13-8834da60a01294fd509c7cebf3b129fcc378d152.zip
chore: changing to ipynb
Diffstat (limited to '_legacy/algorithms/linear_search.py')
-rw-r--r--_legacy/algorithms/linear_search.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/_legacy/algorithms/linear_search.py b/_legacy/algorithms/linear_search.py
new file mode 100644
index 0000000..ae198d2
--- /dev/null
+++ b/_legacy/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()