So, what I was going for, is first of all test if A + one of the Numbers was equal to the total I wanted, and got to this:
Now, what I had planned was to set init (the initial value) to init+testlist[1] and then try with adding testlist[2], testlist[3] and testlist[4]. If it doesn't work, set init to init+testlist[1]+testlist[2] and try adding that value to one of the other values, and so on.
Again, excuse me if I'm not clear enough in my explanations
So, I thought it might be much easier, if I keep using for loops, to use something like that:
testlist=[5,8,23,-12] total=15 init=7 def main(lis, valInit, valsearched): for i in lis: valInit+=i if valInit==total: return i valInit=7 print(main(testlist, init, total))I picked the values so as they work.
Now, what I had planned was to set init (the initial value) to init+testlist[1] and then try with adding testlist[2], testlist[3] and testlist[4]. If it doesn't work, set init to init+testlist[1]+testlist[2] and try adding that value to one of the other values, and so on.
Again, excuse me if I'm not clear enough in my explanations
So, I thought it might be much easier, if I keep using for loops, to use something like that:
for i in lis: for j in range(1, len(lis)): valInit=valInit+i+j if valInit==total: return i