Expense calculator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deathwing
    New Member
    • Mar 2007
    • 32

    Expense calculator

    Hi everyone one I'm playing around with trying to make an expense calculator.
    I would like it so that the user can keep enter expenses until they have no more expenses. Then I would like for the program to give the users total expenses then subtract this from their total income and inform them how much they have left after monthly expenses. Any ideas ? this is what I've come up with thus far.
    Code:
    # Expense calculator
    # This program calculates your total monthly expenses
    
    
    #print"\a"
    
    print\
           """
                            #-----------------#
                            |Montly Expense   |
                            |Calculator 1.0   |
                            #-----------------#
                            
     Welcome to Monthly Expense Calculator 1.0 this calculator
     will ask you a series of questions relating to your monthly
     expenses. It will then calculate your total montly income
     against your expenses and tell you how much of  your take
     home pay you are spending.
           """
    
    print " You have the following options:"
    
    print "\n To enter an expense type '1' otherwise type '2' for no more expenses."
    
    options = ( 'espense = 1', 'noexpense = 2')
    
    while True:
    
        choice = int(raw_input("\nWould you like to enter a monthly expense?"))
    
        if choice == 1:
            expense = (raw_input("\nEnter expense name"))
            cost = float(raw_input("\nEnter total monthly cost of this expense."))
        elif  choice == 2:
            raw_input("\nPress enter to exit.")
            break
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by Deathwing
    Hi everyone one I'm playing around with trying to make an expense calculator.
    I would like it so that the user can keep enter expenses until they have no more expenses. Then I would like for the program to give the users total expenses then subtract this from their total income and inform them how much they have left after monthly expenses. Any ideas ? this is what I've come up with thus far.
    Code:
    # Expense calculator
    # This program calculates your total monthly expenses
    
    
    #print"\a"
    
    print\
           """
                            #-----------------#
                            |Montly Expense   |
                            |Calculator 1.0   |
                            #-----------------#
                            
     Welcome to Monthly Expense Calculator 1.0 this calculator
     will ask you a series of questions relating to your monthly
     expenses. It will then calculate your total montly income
     against your expenses and tell you how much of  your take
     home pay you are spending.
           """
    
    print " You have the following options:"
    
    print "\n To enter an expense type '1' otherwise type '2' for no more expenses."
    
    options = ( 'espense = 1', 'noexpense = 2')
    
    while True:
    
        choice = int(raw_input("\nWould you like to enter a monthly expense?"))
    
        if choice == 1:
            expense = (raw_input("\nEnter expense name"))
            cost = float(raw_input("\nEnter total monthly cost of this expense."))
        elif  choice == 2:
            raw_input("\nPress enter to exit.")
            break
    I'm not exactly sure what you are saying but you might be able to use a dictionary to store the data of the expenses.For example, enter the expense name into the key and make the value the monthly cost.

    Comment

    • ghostdog74
      Recognized Expert Contributor
      • Apr 2006
      • 511

      #3
      using dictionaries might not be suitable for this application as users might want to save data on disk. so another way is to use pickle/shelve or dbm databases. (other others).

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by ghostdog74
        using dictionaries might not be suitable for this application as users might want to save data on disk. so another way is to use pickle/shelve or dbm databases. (other others).
        I thought that pickling worked on dictionaries. Am I wrong about this?

        Comment

        • ghostdog74
          Recognized Expert Contributor
          • Apr 2006
          • 511

          #5
          Originally posted by bartonc
          I thought that pickling worked on dictionaries. Am I wrong about this?
          no, you are not wrong. what i meant in my previous post is, if OP uses just pure dictionaries, whatever data modification to expenses stored in dictionaries will be gone once the program exits. So its good to use some [ pickling/shelving/dbm/files ] to save information to disk so that the expenses can be "remembered " next time the application is used.

          Comment

          • Deathwing
            New Member
            • Mar 2007
            • 32

            #6
            Thanks guys I'll look into your suggestions. I appreicate the help.

            Comment

            Working...