list=[12,1,2,6] t=18 sum=0 for i in range (len(list)+1): for j in list: if t==sum+j: print (j) # j=j+1 #print (j) Tell me why it's not working.
the condition: *if t == sum + j:* will never get True. so no output is given. the variable *sum* is always 0. maybe if you use this variable, do a summing with variable *i* in each iteration and then store the result in the *sum* variable, the condition can get True
Akash Gupta , since i have no helpful task description, you have to find out by yourself where and what to do with the variable *sum*
Akash Gupta Pls describe the task the code should do. We can't fix code we don't know the purpose of. Also, know we should not fix, but help you to fix the code. This is what makes you learn for real.
Emerson Prado task is that you have a list and in the list we have following numbers and you have also a target value then what you want to do is that you want print the value in given list which is equal to target. Like Suppose: list=[12,3,1,6,8,8] target_value=10 Output: 3 1 6
Do you mean print a set of values from given list which sum equals target?
Lothar can you correct this
Lothar how will i iterate j by adding the value in list.
Lothar I'm confused very much please solve that
help my code does not iterate