title: Adding line numbers to the output in Python
body: <p>For example, if the input file is:</p>
  <pre><code>def main():
      for i in range(10):
          print(&quot;I love Python&quot;)
      print(&quot;Good bye!&quot;)
  </code></pre>
  <p>Then the output would be:</p>
  <pre><code>1   def main():
  2       for i in range(10):
  3           print(&quot;I love Python&quot;)
  4       print(&quot;Good bye!&quot;)
  </code></pre>
  <p>I have difficulty in adding lines to each line. My program is:</p>
  <pre><code>filename = input(&quot;Please enter a file name: &quot;)
  count = 0
  
  openfile = open(filename, &quot;r&quot;)
  
  for lines in openfile:
      linenumbers = openfile.write(str(count)+'\t'+lines)
      count += 1
  
  print(count)
  </code></pre>