425,749 Members | 1,574 Online
Need help? Post your question and get tips & solutions from a community of 425,749 IT Pros & Developers. It's quick & easy.

# Expense calculator

 P: 32 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. Expand|Select|Wrap|Line Numbers # 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             Apr 19 '07 #1
5 Replies

 Expert 100+ P: 844 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. Expand|Select|Wrap|Line Numbers # 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. Apr 19 '07 #2

 Expert 100+ P: 511 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). Apr 19 '07 #3

 Expert 5K+ P: 6,596 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? Apr 20 '07 #4

 Expert 100+ P: 511 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. Apr 20 '07 #5

 P: 32 Thanks guys I'll look into your suggestions. I appreicate the help. Apr 23 '07 #6