title: Python: variable initialization and for loop
body: <p>I have a list of <code>int</code> ranging from <code>0</code> to <code>99</code>, for instance <code>center_nodes=[51,52]</code>, and I want to perform a simple operation:</p>
  
  <p>Take the first element, <code>center_nodes[0]</code>, get its first figure, <code>first=str(center_nodes[0])[0]</code>, and then add an <code>int</code> to it based on the figure itself.</p>
  
  <p>Example: if <code>first=5</code>, then <code>result=int(center_nodes[0])+int(first)</code>. In this case it should yield <code>56</code>.</p>
  
  <p>I wrote a piece of code to do this but I always get <code>0</code>. There must be some very stupid mistake I have made, and I suspect it lies in the initialization of the <code>result</code> variable, which in the script is called <code>grid_coord</code>.</p>
  
  <p>My attempt:</p>
  
  <pre><code>#code block to compute the center_nodes[] list
  #here comes my script:
  first=str(center_nodes[0])[0] #Get the first figure of element 0 of center_nodes
  print('first figure: '+str(first))
  grid_coord=None
  if len(str(center_nodes[0]))==1: #Check if center_nodes[0] is in the 0-9 range
      grid_coord=int(first)
      print('Grid coord for center giant comp is: '+str(grid_coord))
  elif len(str(center_nodes[0]))==2: #Check if center_nodes[0] is in the 10-99 range
      if first==1: #Checks the first digit of center_nodes[0] and then adds it to int(center_nodes[0])
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
      if first==2: #Check the second digit...
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
      if first==3: #Check the third digit...
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
      if first==4: #4th
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
      if first==5: #5th
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
      if first==6: #6th
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
      if first==7: #7th
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
      if first==8: #8th
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
      if first==9: #9th and last
          grid_coord=int(center_nodes[0])+int(first)
          print('Grid coord for center giant comp is: '+str(grid_coord))
  </code></pre>
  
  <p>For <code>center_nodes=[51,52]</code>, I should get <code>grid_coord=56</code>, but I get <code>grid_coord=0</code> instead. What should I change?</p>