diff --git a/main.py b/main.py index 22dfeb69e9534f28c03cc0554487f8e0f7985ea0..87f76379c70cbe884b6f8bc3f7c87dbfceed29b7 100755 --- a/main.py +++ b/main.py @@ -6,21 +6,25 @@ Find sum of 2 numbers to match a given number import random MAX = 100 -SAMPLE_SIZE = 10 +SAMPLE_SIZE = 5 def main(): """ main driver program """ - the_list = random.sample(range(MAX), SAMPLE_SIZE) + the_list = (random.sample(range(MAX), SAMPLE_SIZE) + + random.sample(range(MAX), SAMPLE_SIZE)) the_num = random.randint(1, MAX) print(the_list, the_num) - print(any(the_num - item in the_list for item in the_list)) + print(any(the_num - item in the_list[n+1:] + for n, item in enumerate(the_list))) for i in the_list: - if the_num - i in the_list: + val = the_num - i + count = the_list.count(val) + if count > 1 or (count and val != i): print("True ", the_num - i, i) break else: