title: Reading File and Printing Output
body: <p>I am reading a file and the output is supposed to look like the one below, ignoring the actual table the values for my hours,minutes and seconds are off as is the money, which is supposed to be calculated by rounding up to the minute; I have tried many ways to solve this and this is my last resort. </p>
  
  <pre><code>+--------------+------------------------------+---+---------+--------+
  | Phone number | Name                         | # |Duration | Due    |
  +--------------+------------------------------+---+---------+--------
  
  
  |(780) 123 4567|Ameneh Gholipour Shahraki     |384|55h07m53s|$ 876.97|**
  |(780) 123 6789|Stuart Johnson                |132|17h53m19s|$ 288.81|
  |(780) 321 4567|Md Toukir Imam                |363|49h52m12s|$ 827.48|++
  |(780) 432 1098|Hamman Samuel                 |112|16h05m09s|$ 259.66|
  |(780) 492 2860|Osmar Zaiane                  |502|69h27m48s|$1160.52|**
  |(780) 789 0123|Elham Ahmadi                  |259|35h56m10s|$ 596.94|
  |(780) 876 5432|Amir Hossein Faghih Dinevari  |129|17h22m32s|$ 288.56|
  |(780) 890 7654|Weifeng Chen                  |245|33h48m46s|$ 539.41|
  |(780) 987 6543|Farrukh Ahmed                 |374|52h50m11s|$ 883.72|**
  +--------------+------------------------------+---+---------+--------+
  | Total dues   |                                          $   5722.07|
  +--------------+-----------------------------------------------------+
  </code></pre>
  
  <p>This is my code and I am having the most trouble with the time() and due() functions</p>
  
  <pre><code>from collections import Counter
  
  customers=open('customers.txt','r')
  calls=open('calls.txt.','r')
  
  def main():
      customers=open('customers.txt','r')
      calls=open('calls.txt.','r')    
      print("+--------------+------------------------------+---+---------+--------+")
      print("| Phone number | Name                         | # |Duration | Due    |")
      print("+--------------+------------------------------+---+---------+--------+")
      phone_sorter() 
      number_calls()
      time()
      due()
  def phone_sorter():
      sorted_no={}
      for line in customers:
          rows=line.split(";")
          sorted_no[rows[1]]=rows[0]
      for value in sorted(sorted_no.values()):
              for key in sorted_no.keys():
                  if sorted_no[key] == value:
                      print(sorted_no[key],key)
  
  def number_calls():
      no_calls={}
      for line in calls:
          rows=line.split(";")
          if rows[1] not in no_calls:
              no_calls[rows[1]]=1
          else:
              no_calls[rows[1]]+=1
  
      s=sorted(no_calls.keys())
      for key in s:
          print(no_calls[key])
  
  
  def time():
      calls=open('calls.txt.','r')  
      n_list=[]
      d={}
      for line in calls:
          rows=line.split(";")
          d[rows[1]]=rows[3]
          if rows[1] not in d:
              d[rows[1]]=rows[3]
          else:
              d[rows[1]]+=rows[3]
  
      x=sorted(d.keys())
  
      for value in x:
          m, s = divmod(int(value), 60)
          h, m = divmod(m, 60)
          print("%d:%02d:%02d" % (h, m, s)) 
  
  def due():
      calls=open('calls.txt.','r')
      d2={}
      for line in calls:
          rows=line.split(";")
          d2[rows[1]]=float(rows[3])*float(rows[4])
          if rows[1] not in d2:
              d2[rows[1]]=float(rows[3])*float(rows[4])
          else:
              d2[rows[1]]+=float(rows[3])*float(rows[4])
      x=sorted(d2.keys())
      for key in x:
          print(d2[key])
      print(sum(d2.values()))
  
  main()
  </code></pre>
  
  <p>This is the link to the file I am reading in pastebin: <a href="http://pastebin.com/RSMnXDtq" rel="nofollow">http://pastebin.com/RSMnXDtq</a></p>
  
  <p>The first column is for the phone number. This number has to be formatted as (999) 999 9999.</p>
  
  <p>The second column is for the name and it has to be 30 characters wide.</p>
  
  <p>The third column is for the number of calls originating from the phone in question. It should be on 3 digits.</p>
  
  <p>The fourth column is for the total duration of the calls originating from the phone in question. This duration should be formatted as follows: 99h99m99s for hours, minutes and seconds. The minutes and seconds should have a prefix of 0 if less than 10.</p>
  
  <p>The fifth column is for the amount paid for the calls calculated based on the rates attached to each call. Note that the duration for each call should be rounded up to the minute in order to use the rate per minute. This amount should be printed with 7 positions and only 2 after the decimal point.</p>