From 7fbfc8fd0325dc4c6256bad421ab316435bffd23 Mon Sep 17 00:00:00 2001 From: Benjamin Adovasio Date: Tue, 3 Mar 2026 23:14:27 -0500 Subject: [PATCH] added code to ensure 42 in list --- Project 3/project_3_search.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Project 3/project_3_search.py b/Project 3/project_3_search.py index cf7769b..1854c8a 100644 --- a/Project 3/project_3_search.py +++ b/Project 3/project_3_search.py @@ -21,8 +21,9 @@ class Search: for _ in range(n): array.append(random.randint(0, 1000)) - # if 42 not in data: - # data[random.randint(0, n - 1)] = 42 + #I added this for testing purposes, to make sure 42 was in the list + if 42 not in array: + array[random.randint(0, n - 1)] = 42 return array @@ -34,7 +35,7 @@ class Search: for value in arr: if value == target: print("Unsuccessful checks:", checks) - + return checks checks += 1 print("Not found.") @@ -98,8 +99,8 @@ def main(): n = 1000 arr = search.generate_random_list(n) #generate the list of n random integers - for multiplier in [0.5, 1, 2, 4]: - query_count = int(n * multiplier) + for multiplier in [0.5, 1, 2, 4]: #I used a "multiplier" to avoid rewriting the code for each query + query_count = int(n * multiplier) queries = [] for _ in range(query_count):