Two Sum. I use a nested loop but it seems not work
<pre><code>class Solution(object)
  def twoSum(self,num,target):
    #nested for loop, but the result shows only the inner loop works

    for i in range(0,len(num)-1,1):
       for j in range(i+1,len(num),1):
             target=target-num[i]-num[j]
             if target!=0:
                target=target+num[i]+num[j]
             else:
                break

        return i,j
Solution().twoSum([0,1,1,3,0],4)
</code></pre>

<p>Output:(0, 4) #the first number never changes and always be zero.So I think it may be the problem of the outer loop, but why and what can I do to make it work? </p>

<p>Since you're not telling your goal, I guess that you're looking for sort of solution like this?<br /></p>

<pre><code>class Solution(object):
    def twoSum(self, num, target):
        ans = []
        for i in range(len(num) - 1):
            for j in range(i + 1, len(num)):
                s = num[i] + num[j]
                if s == target:
                    ans.append((i, j))
        return ans

print Solution().twoSum([0, 1, 1, 3, 0], 4)
</code></pre>

<p>People would really just feel confused if you just ask this way.</p>

python output