title: python3.x list assignment index out of range
body: <p>log：IndexError: list assignment index out of range</p>
  
  <p>I can not fix.list assignment index out of range. Can you help me ?</p>
  
  <hr>
  
  <pre><code>  j=1
      n=int(input())
      flag=[]*29
      a=[]*29
      for i in range(len(a)):
          a[i]=1.0/(i+2)
      for j in range(2**29):
          temp=j
          index=0
          sum=0
          while temp&gt;0 and index&lt;29:
              flag[index]=temp%2
              index=index+1
              sum+=(temp%2)*a[index]
              temp=temp/2
      if sum==1:
          count=0
          index=index+1
          for i in range(index):
              if flag[i]==1:
                  count+=1
          if count==n:
              for i in range(len(flag)):
                  if flag[i]!=0:
                      print(flag[i]+"/"+(i+2)+"")
  </code></pre>