By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,749 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,749 IT Pros & Developers. It's quick & easy.

Expense calculator

Deathwing
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
  1. # Expense calculator
  2. # This program calculates your total monthly expenses
  3.  
  4.  
  5. #print"\a"
  6.  
  7. print\
  8.        """
  9.                         #-----------------#
  10.                         |Montly Expense   |
  11.                         |Calculator 1.0   |
  12.                         #-----------------#
  13.  
  14.  Welcome to Monthly Expense Calculator 1.0 this calculator
  15.  will ask you a series of questions relating to your monthly
  16.  expenses. It will then calculate your total montly income
  17.  against your expenses and tell you how much of  your take
  18.  home pay you are spending.
  19.        """
  20.  
  21. print " You have the following options:"
  22.  
  23. print "\n To enter an expense type '1' otherwise type '2' for no more expenses."
  24.  
  25. options = ( 'espense = 1', 'noexpense = 2')
  26.  
  27. while True:
  28.  
  29.     choice = int(raw_input("\nWould you like to enter a monthly expense?"))
  30.  
  31.     if choice == 1:
  32.         expense = (raw_input("\nEnter expense name"))
  33.         cost = float(raw_input("\nEnter total monthly cost of this expense."))
  34.     elif  choice == 2:
  35.         raw_input("\nPress enter to exit.")
  36.         break
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
Apr 19 '07 #1
Share this Question
Share on Google+
5 Replies


ilikepython
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
  1. # Expense calculator
  2. # This program calculates your total monthly expenses
  3.  
  4.  
  5. #print"\a"
  6.  
  7. print\
  8.        """
  9.                         #-----------------#
  10.                         |Montly Expense   |
  11.                         |Calculator 1.0   |
  12.                         #-----------------#
  13.  
  14.  Welcome to Monthly Expense Calculator 1.0 this calculator
  15.  will ask you a series of questions relating to your monthly
  16.  expenses. It will then calculate your total montly income
  17.  against your expenses and tell you how much of  your take
  18.  home pay you are spending.
  19.        """
  20.  
  21. print " You have the following options:"
  22.  
  23. print "\n To enter an expense type '1' otherwise type '2' for no more expenses."
  24.  
  25. options = ( 'espense = 1', 'noexpense = 2')
  26.  
  27. while True:
  28.  
  29.     choice = int(raw_input("\nWould you like to enter a monthly expense?"))
  30.  
  31.     if choice == 1:
  32.         expense = (raw_input("\nEnter expense name"))
  33.         cost = float(raw_input("\nEnter total monthly cost of this expense."))
  34.     elif  choice == 2:
  35.         raw_input("\nPress enter to exit.")
  36.         break
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
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

bartonc
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

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

Post your reply

Sign in to post your reply or Sign up for a free account.