calculating from a file

Discussion in 'Python' started by trade19, Apr 5, 2014.

  1. trade19

    trade19 New Member

    Joined:
    Mar 29, 2014
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    HI I want to ask how I can open a file like this one:
    and add together each line (each time the program runs it could add more lines) amount of lines could change below are six.
    I want to get a total from these
    below would be $28.00 The floats would always be .00
    I think these are integer amounts
    I am not sure rite now why the program is putting out $0.00 but never mind that.
    thanks for any help

    Code:
    $0.00 
    $10.00 
    $0.00 
    $10.00 
    $0.00 
    $8.00 
    
    
    totals= open("C:\\write_it.txt", "r")
    totals.read(totalc)
    Label(aApp,text= "You purchased: $%.2f \n" %  totalc, font=('times', 10, 'bold')).grid(row=0,column=0)
    print('total-c', totalc)
    totals.close()
     
  2. trade19

    trade19 New Member

    Joined:
    Mar 29, 2014
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    also this is how i fed the file

    Code:
    totals = open("C:\\write_it.txt", "a")
    totals.write('$%.2f \n'  % totalc)
    print('This is total-C', totalc)
    totals.close()
    print('total',total,'total b',totalb,'total-c',totalc)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice