title: Reversing lines from a file Python 3
body: <p>I am trying to make lines from a text file in Python 3 be reversed and written to an outfile. Currently, I am having issues with the last line of the infile not containing \n on the end of the line. I am getting a TypeError from this code. </p>
  
  <pre><code>def main():
  
      endofprogram = False
      try:
          inputfile = input("Enter name of input file: ")
  
          ifile = open(inputfile, "r", encoding="utf-8")
  
          outputfile = input("Enter name of output file: ")
          while os.path.isfile(outputfile):
              if True:
                  outputfile = input("File Exists. Enter name again: ")        
          ofile = open(outputfile, "w")        
  
  
      except IOError:
          print("Error opening file - End of program")
          endofprogram = True
  
      #If there is not exception, start reading the input file
  
      if endofprogram == False:
          newline = "\n"
          for line in ifile:
              line = line.strip            
              line = line + "\n"            
              lines = ifile.readlines()
  
      lines.reverse()
      newlines= "".join(lines)
      print(newlines)     
      ifile.close()
      ofile.close()
  
  main() # Call the main to execute the solution
  </code></pre>