title: Reading from a .txt file and printing in a table form
body: <p>So how can I manipulate a piece of code so that it reads from a .txt file and prints the data in a table format with headings such as 'Resident Number' 'Rent date' 'Price' etc.? The name of the file is Residents.txt </p>
  
  <p>So far, I have this </p>
  
  <pre><code>file = open('Residents.txt','r')
  For line in file:
      SplitFile = line.split (',')
  </code></pre>
  
  <p>This is the .txt file-<br>
  R1,21/09/2015,C1,440,P,0<br>
  R2,21/09/2015,C3,290,A,290<br>
  R3,21/09/2015,C4,730,N,0<br>
  R4,22/09/2015,C5,180,A,180<br>
  R5,22/09/2015,C6,815,A,400<br>
  R6,23/09/2015,C7,970,N,0<br>
  R7,23/09/2015,C8,1050,P,0<br>
  R8,23/09/2015,C9,370,A,200<br>
  R9,25/09/2015,C10,480,A,250<br>
  R10,25/09/2015,C11,330,A,330         </p>
  
  <p>This is the representation of each column in the .txt file- </p>
  
  <pre><code>line.split[0] = Resident Number      
  line.split[1] = Rent Date       
  line.split[2] = Customer number        
  line.split[3] = Rent amount         
  line.split[4] = (A means Accepted)(N means not accepted)(P means Pending)          
  line.split[5] = Amount paid    
  </code></pre>
  
  <p>PLEASE NOTE-<br>
  if amount paid equals to rent amount, that residents data shouldn't be shown in the table<br>
  if status is N or P, that residents data should also not be shown in the table</p>
  
  <p>How can I display a table (WITHOUT importing modules) which has headings of 'Resident number' 'Rent date' 'Customer number' 'Rent amount' 'Amount outstanding'- amount outstanding is just rent amount - amount paid from that line. Also, how can I print a ultimate total of the outstanding amount of money (combined total for everyone that is yet to pay with a status of 'A') </p>
  
  <p>Python 3.5</p>
  
  <p>Thanks    </p>
  
  <p>EDIT</p>
  
  <pre><code>for i, word in enumerate(line):
          if i == 4 :  # We don't print the status
              continue
          elif i == 2:
              continue
          print(word.ljust(len(headers[i - (i &gt; 4)(i &gt; 2)])), end="    " * ((i - (i &gt; 4)(i &gt; 2)) != len(headers) - 1))
  print()
  </code></pre>
  
  <p>FURTHER EDIT (15/02)</p>
  
  <pre><code>line = line.strip().split(",")
      subtotal = int(line[3]) - int(line[5])
      line.append(str(subtotal))
      if line[5] == line[3] or line[4] in ("N", "E"):
          continue
      total += subtotal
  </code></pre>