0

I have two list of elements:

p1_test = [10,5,7]
board_test = [4,7,3,9]

I have to take one element from p1_test and check if there is a chance of sum 15 with the elements of board_test. From p1_test only can take one element, from board_test it could take the elements that were necessary.

I've tried to create a function that returns True if I can sum 15

def chance_get_15():

    for a in p1_test:
        board_sum = a
        for b in board_test:
            board_sum += b
            if board_sum == 15:
                print('there is a chance')
                return True
            elif board_sum > 15:
                board_sum = board_sum - b
                continue

If I run that, It doesn't return True. I want this to return True because, if I take the second element of p1_test (5) and sum with the second and the third element of board_test (7 and 3) it should return True. But I have not been able to translate that into python code.

The list board_test is a variable list, it could have more or less elements, depend on the situation.

Migue
  • 9
  • 1
  • You can use the code in the proposed duplicate, just adjust the "certain number" down by the value you take from `p1_test` – Nick May 31 '22 at 04:11

0 Answers0