Aug-13-2020, 02:32 PM
There are only two numbers that add up to 24; 4 + 20, and they are both in the same list. You cannot add a number from list1 to a number from list2 to get 24. If you are just looking for two different numbers and the numbers can be from either list, the answer is 4 and 20
To solve the answer using one number from each list:
To solve the answer using one number from each list:
for a in list1: for b in list2: if a + b == 24: print(f'{a} + {b} = 24')Tp solve for any combination of numbers in either list:
numbers = list1 + list2 for a in numbers: for b in numbers: if a + b == 24: print(f'{a} + {b} = 24')This could be made more efficient if the lists were large or if you wanted to avoid double answers (4, 20 and 20, 4)