Expand|Select|Wrap|Line Numbers
- #This program will help a person keep their budget
- totalBudget = 4000
- #the main function
- def main ():
- print 'Welcome to my personal budget calculator'
- choice ()
- #this function will start the menu selection
- def choice ():
- print 'Menu Selection'
- print '1 - Add an Expense'
- print '2 - Remove an Expense'
- print '3 - Add a Revenue'
- print '4 - Remove a Revenue'
- print '5 - Exit'
- selection = input ('Enter menu selection ')
- while selection !=5:
- if selection == 1:
- addExpense (totalBudget)
- if selection == 2:
- removeExpense (totalBudget)
- if selection == 3:
- addRevenue (totalBudget)
- if selection == 4:
- removeRevenue (totalBudget)
- if selection == 5:
- print 'Goodbye'
- #this function will add an expense
- def addExpense (totalBudget):
- addAmount = input ('Enter the amount of the expense to be added. ')
- addFrequency = input ('Enter the frequency of the expense. ')
- addTotal = addAmount * addFrequency
- if totalBudget > addTotal:
- totalBudget = totalBudget - addTotal
- print 'The new budget is', totalBudget
- return totalBudget
- elif totalBudget < addTotal:
- print 'The expense exceeds current budget. Try again'
- #this function will remove an expense
- def removeExpense (totalBudget):
- removeAmount = input ('Enter the amount of the expense to be removed. ')
- removeFrequency = input ('Enter the frequency of the expense. ')
- removeTotal = removeAmount * removeFrequency
- if removeTotal > totalBudget:
- print 'Expenses exceed the budget. Try again.'
- elif removeTotal < totalBudget:
- totalBudget = totalBudget + removeTotal
- print 'The new budget is', totalBudget
- return totalBudget
- #this function will add a revenue
- def addRevenue (totalBudget):
- addIncome = input ('Enter the amount of the revenue to be added. ')
- totalBudget = addIncome + totalBudget
- print 'Your new budget is', totalBudget
- return totalBudget
- #this function will remove a revenue
- def removeRevenue (totalBudget):
- removeIncome = input ('Enter the amount of the revenue to be removed. ')
- if removeIncome > totalBudget:
- print 'Your income exceeds budget. Try again.'
- elif removeIncome < totalBudget:
- totalBudget = totalBudget - removeIncome
- print 'Your new budget is', totalBudget
- return totalBudget
- main()