I'm trying to put the sum of two numbers from list x of which the division by 20 of that sum is not possible into list z. My code does not comply with the rule that only a combination of two numbers from list x can be used. So, for instance, 35 is not valid since it can't be formed by adding two numbers from list x. However, it still occurs in the result of list z.
Also, I'm adding up 'target' by 5 since 5 is the lowest number in list x.
What am I doing wrong?
x = [200, 100, 50, 20, 10, 5]
target = 5
combi=0
max = x[0]+x[1]
z = []
while target <= max:
for i in x:
if i < target:
pair = target - i
if pair in x:
combi = 1
if combi == 1 and target % 20 != 0:
z.append(target)
target += 5
print(z)
Given output: [10, 15, 25, 30, 35, 45, 50, 55, 65, 70, 75, 85, 90, 95, 105, 110, 115, 125, 130, 135, 145, 150, 155, 165, 170, 175, 185, 190, 195, 205, 210, 215, 225, 230, 235, 245, 250, 255, 265, 270, 275, 285, 290, 295]
Desired output: [10, 15, 25, 30, 55, 70, 105, 110, 150, 205, 210, 250]
combito 0. Thecombi = 0assignment should be moved inside thewhileloop