summaryrefslogtreecommitdiff
path: root/lesson1.py
diff options
context:
space:
mode:
Diffstat (limited to 'lesson1.py')
-rw-r--r--lesson1.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/lesson1.py b/lesson1.py
index a2f7741..11cbd8f 100644
--- a/lesson1.py
+++ b/lesson1.py
@@ -8,13 +8,17 @@ def linear_search_while(arr: list, item):
found: bool = False
index = 0
while not found and index < len(arr):
- if (arr[index] == item): found = True
+ if (arr[index] == item):
+ found = True
+ break
index += 1
- return found
+ return (found, index)
def linear_search(arr: list, item):
+ index = 0
for _item in arr:
if _item == item:
- return True
+ return (True, index)
+ index += 1
return False
def main():
print("Hello world")
@@ -23,7 +27,12 @@ def main():
query = int(input("Your query for item: "))
found1 = linear_search(array, query)
found2 = linear_search_while(array, query)
- print("Found by for loop method") if found1 else print("Not found.")
- print("Found by while loop method") if found2 else print("Not found.")
+ if found1[0]:
+ print("Found by for loop method ", found1[1])
+ else: print("Not found.")
+ if found2[0]:
+ print("Found by while loop method ", found2[1])
+ else:
+ print("Not found.")
if __name__ == "__main__":
main() \ No newline at end of file