0
Hello everyone
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.
8 odpowiedzi
+ 7
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
+ 5
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*
+ 2
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.
+ 1
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
+ 1
Do you mean print a set of values from given list which sum equals target?
0
Lothar can you correct this
0
Lothar how will i iterate j by adding the value in list.
0
Lothar I'm confused very much please solve that