-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge.py
More file actions
58 lines (49 loc) · 1.73 KB
/
challenge.py
File metadata and controls
58 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# create array 1
array1 = []
# create array 2
array2 = []
# create solution
solution = []
# get the target value
target_value = int(input("What is the target value? "))
# how many number go in the first array
array1_len = int(input("How many numbers go in the first list? "))
# how many number fo in the second array
array2_len = int(input("How many numbers go in the second list? "))
# get first arrays value
for i in range(1, array1_len + 1, 1):
num_array1 = int(input("number " + str(i) + " in list 1: "))
array1.append(num_array1)
# get second arrays value
for i in range(1, array2_len + 1, 1):
num_array2 = int(input("number " + str(i) + " in list 2: "))
array2.append(num_array2)
# create function
def check(array1, array2, target_value):
# go through first array
for i in range(0, array1_len, 1):
# print(i)
# go through second array
for j in range(0, array2_len, 1):
# check how far the first pair is from the target value is
if i == 0 and j == 0:
closest = target_value - array1[i] - array2[j]
# print(closest)
the_arr = [array1[i], array2[j]]
# check all the other options
else:
check_closest = target_value - array1[i] - array2[j]
if abs(check_closest) < abs(closest):
closest = check_closest
the_arr = [array1[i], array2[j]]
elif abs(check_closest) == abs(closest):
the_arr.append(array1[i])
the_arr.append(array2[j])
print(the_arr)
# print(the_array2)
# go through second array
# compare array
# save values if they are near target value
# create function
# call function with parameters
check(array1, array2, target_value)