Write a program in Python 3.5 that reads a file, then writes a different file with the same text that was in the first one as well as more?
<p>The exact question to this problem is:
*Create a file with a 20 lines of text and name it âlines.txtâ. Write a program to read this a file âlines.txtâ and write the text to a new file, ânumbered_lines.txtâ, that will also have line numbers at the beginning of each line.
Example: 
Input file: âlines.txtâ</p>

<pre><code>Line one
Line two
</code></pre>

<p>Expected output file:</p>

<pre><code>1 Line one
2 Line two
</code></pre>

<p>I am stuck, and this is what I have so far. I am a true beginner to Python and my instructor does not make things very clear. Critique and help much appreciated.</p>

<pre><code>file_object=open("lines.txt",'r')
for ln in file_object:
    print(ln)

count=1
file_input=open("numbered_lines.txt",'w')
for Line in file_object:
    print(count,' Line',(str))
    count=+1
file_object.close
file_input.close
</code></pre>

<p>All I get for output is the .txt file I created stating lines 1-20. I am very stuck and honestly have very little idea about what I am doing. Thank you</p>

<p>The right way to open a file is using a <code>with</code> statement:</p>

<pre><code>with open("lines.txt",'r') as file_object:
    ... # do something
</code></pre>

<p>That way, the context manager introduced by <code>with</code> will close your file at the end of "something " or in case of exception.</p>

<p>Of course, you can close the file yourself if you are not familiar with that. Not that <code>close</code> is a method: to call it you need parenthesis:</p>

<pre><code>file_object.close()
</code></pre>

<p>See the chapter 7.2. <a href="https://docs.python.org/3.5/tutorial/inputoutput.html" rel="nofollow">Reading and Writing Files</a>, in the official documentation. </p>

python file