8 Replies - 8123 Views - Last Post: 19 May 2010 - 01:01 AM Rate Topic: -----

#1 MGWalden  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 30-April 09

Personal Budget Program

Post icon  Posted 06 May 2009 - 12:08 PM

I am having problems with my budget program. I am getting a math error when I enter 500 for expence times 6 (this is under my budget) it commes back thet I have gone over budget but it says I have 1000 available.

Thanks in advance,
Michael Walden
mgwalden@gmail.com


#'Michael Walden IT104 Final Project C'
def main():
	endProgram = 'no'
	integerchoice=0
	totalBudget=4000
	while endProgram == 'no':
		print
		print 'Welcome to the Personal Budget Program'
		print 'Menu Selections: '
		print '1-Add an Expense: '
		print '2-Remove an Expense: '
		print '3-Add Revenue: '
		print '4-Remove Revenue: '
		print '5-Check Budget Balance: '
		print '6-Exit'	 
		print
		choice=int(raw_input('enter your selection: '))
		if choice == 1:
				totalBudget = addExpense(totalBudget)
		elif choice == 2:
				totalBudget = removeExpense(totalBudget)
		elif choice == 3:
				totalBudget = addRevenue(totalBudget)
		elif choice == 4:
				totalBudget = removeRevenue(totalBudget)
		elif choice == 5:
			 print 'Your balance is',totalBudget
		elif choice == 6:
			 endProgram = 'yes'
			 print 'Thank you for using my budget program, Goodbye'
		elif choice > 6: 
			print 'Invalid selection, please try again'
		
	  
def addExpense(totalBudget):
	expense = input ('Enter your expense amount: $')
	monthly = input ('How many times per month: ')
	totalExpense = expense * monthly
	totalBudget= totalBudget - totalExpense
	if totalExpense >= totalBudget:
		print ('The expenses was rejected because the budget exceeded.'),totalBudget
		totalBudget >= totalExpense   
	else:
		print ('The expenses was accepted, your remaining budget is: $'),totalBudget
	choice=int(raw_input('enter your selection: '))
	return totalBudget
	

def removeExpense (totalBudget):
	expense = input ('Enter expense amount you want to remove: $')
	monthly = input ('How many times per month: ')
	totalExpense = expense * monthly
	totalBudget=totalExpense+totalBudget
	print('your remaining budget is: $%.2f' )%totalBudget
	return totalBudget

def addRevenue (totalBudget):
	revenue = input ('Enter new monthly income: $')
	totalBudget = totalBudget+revenue
	print ('your new budget is: $%.2f') %totalBudget
	return totalBudget	

def removeRevenue (totalBudget):
	revenue = input ('Enter monthly income amount to be removed: $')
	totalBudget = totalBudget - revenue
	if revenue >=totalBudget:
		print ('You owe :$%.2f')  %totalBudget
	else:
			print ('Your new budget is: $%.2f') %totalBudget
	return totalBudget


main()




{OUTPUT}
Welcome to the Personal Budget Program
Menu Selections:
1-Add an Expense:
2-Remove an Expense:
3-Add Revenue:
4-Remove Revenue:
5-Check Budget Balance:
6-Exit

enter your selection: 1
Enter your expense amount: $500
How many times per month: 6
The expenses was rejected because the budget exceeded. 1000
enter your selection:

Is This A Good Question/Topic? 0
  • +

Replies To: Personal Budget Program

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,421
  • Joined: 23-August 08

Re: Personal Budget Program

Posted 06 May 2009 - 01:46 PM

You passed your total budget into the function, then changed it by subtracting your expense. Comments inline.

def addExpense(totalBudget):
    # totalBudget = 4000
    expense = input ('Enter your expense amount: $')
    monthly = input ('How many times per month: ')
    totalExpense = expense * monthly
    # totalExpense = 3000 (500 x 6 you said)
    totalBudget= totalBudget - totalExpense
    # totalBudget = 1000
    # How is this going to evaluate now?
    if totalExpense >= totalBudget:
        print ('The expenses was rejected because the budget exceeded.'),totalBudget
        totalBudget >= totalExpense  
    else:
        print ('The expenses was accepted, your remaining budget is: $'),totalBudget
    choice=int(raw_input('enter your selection: '))
    return totalBudget

Was This Post Helpful? 1

#3 MGWalden  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 30-April 09

Re: Personal Budget Program

Posted 06 May 2009 - 02:36 PM

OK, but I don't see the fix. Do I need to rewrite so that the adjusted budget is used instead to totalBudget?
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,421
  • Joined: 23-August 08

Re: Personal Budget Program

Posted 07 May 2009 - 08:47 AM

You don't see the fix? Think about it!

You have $1000, and you want to buy a TV that costs $600. Do you subtract the cost of the TV from your $1000, THEN compare the cost of the TV to what you have after you've ALREADY subtracted the cost to determine whether you can afford it?

Simple logic, dude.
Was This Post Helpful? 0
  • +
  • -

#5 MGWalden  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 30-April 09

Re: Personal Budget Program

Posted 07 May 2009 - 01:15 PM

OK, I am pulling a brain fart. so what I need to do is to incert a line for adjBudget, so I can keep the total busget pure? Or do I just have that section writen wrong? I think I see what you are talking ablout in that I am changing the value of the totalBudget line. I just feel like I am missing a simple fix.

Michael Walden
mgwalden@gmail.com
Was This Post Helpful? 0
  • +
  • -

#6 MGWalden  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 30-April 09

Re: Personal Budget Program

Posted 08 May 2009 - 07:33 PM

View PostMGWalden, on 7 May, 2009 - 12:15 PM, said:

OK, I am pulling a brain fart. so what I need to do is to incert a line for adjBudget, so I can keep the total busget pure? Or do I just have that section writen wrong? I think I see what you are talking ablout in that I am changing the value of the totalBudget line. I just feel like I am missing a simple fix.

Michael Walden
mgwalden@gmail.com

Was This Post Helpful? 0
  • +
  • -

#7 MGWalden  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 30-April 09

Re: Personal Budget Program

Posted 08 May 2009 - 07:39 PM

OK, I fixed it. I moved the sutraction line to under the else. Any suggestions to make it nicer?

#'Michael Walden IT104 Final Project C'
def main():
	endProgram = 'no'
	integerchoice=0
	totalBudget=4000
	while endProgram == 'no':
		print
		print 'Welcome to the Personal Budget Program'
		print 'Menu Selections: '
		print '1-Add an Expense: '
		print '2-Remove an Expense: '
		print '3-Add Revenue: '
		print '4-Remove Revenue: '
		print '5-Check Budget Balance: '
		print '6-Exit'	 
		print
		userInput = raw_input('enter your selection: ')
		if userInput != "":
			choice=int(userInput)
			if choice == 1:
					totalBudget = addExpense(totalBudget)
			elif choice == 2:
					totalBudget = removeExpense(totalBudget)
			elif choice == 3:
					totalBudget = addRevenue(totalBudget)
			elif choice == 4:
					totalBudget = removeRevenue(totalBudget)
			elif choice == 5:
				 print 'Your balance is',totalBudget
			elif choice == 6:
				 endProgram = 'yes'
				 print 'Thank you for using my budget program, Goodbye'
			elif choice >= 6:
				print 'Invalid selection, please try again'
			else:
				print 'Invalid selection, please try again'
		
	  
def addExpense(totalBudget):
	expense = input ('Enter your expense amount: $')
	monthly = input ('How many times per month: ')
	totalExpense = expense * monthly
	if totalExpense >= totalBudget:
		print ('The expenses was rejected because the budget exceeded.'),totalBudget
	else:
		totalBudget= totalBudget - totalExpense
		print ('The expenses was accepted, your remaining budget is: $'),totalBudget
	choice=int(raw_input('enter your selection: '))
	return totalBudget

	

def removeExpense (totalBudget):
	expense = input ('Enter expense amount you want to remove: $')
	monthly = input ('How many times per month: ')
	totalExpense = expense * monthly
	
	totalBudget=totalExpense+totalBudget
	print('your remaining budget is: $%.2f' )%totalBudget
	return totalBudget

def addRevenue (totalBudget):
	revenue = input ('Enter new monthly income: $')
	totalBudget = totalBudget+revenue
	print ('your new budget is: $%.2f') %totalBudget
	return totalBudget	

def removeRevenue (totalBudget):
	revenue = input ('Enter monthly income amount to be removed: $')
	totalBudget = totalBudget - revenue
	if revenue >=totalBudget:
		print ('You owe :$%.2f')  %totalBudget
	else:
			print ('Your new budget is: $%.2f') %totalBudget
	return totalBudget


main()



Was This Post Helpful? 0
  • +
  • -

#8 Ed_Bighead  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 178
  • Joined: 26-April 09

Re: Personal Budget Program

Posted 09 May 2009 - 08:36 PM

You don't really need this, just the else will suffice:
elif choice >= 6:
				print 'Invalid selection, please try again'

Was This Post Helpful? 0
  • +
  • -

#9 johnspee5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-May 10

Re: Personal Budget Program

Posted 19 May 2010 - 01:01 AM

I am working on the same final project. My question is about the requirements more than the code. It says in the Specifications "The Remove Expense should prompt the user for the expense amount and its monthly frequency. If the expense amount to be removed exceeds whatever has been used of the current budget, then a message should be displayed to recheck the expense amounts. Otherwise the remaining budget will be increased by the amount of the expense reduction and a message displayed stating the amount of the currently available budget funds. Any ideas what they want here? Do they want a previously entered amount to be able to be recalled at a later time to see if it matches the amount I want to remove?
This is what I have:
#Main Selection Menu
def main():
    totalBudget = 4000
    choice = 0
    while choice != '5':
        print 'Menu Selection'
        print ' 1 = Add an Expense'
        print ' 2 = Remove an Expense'
        print ' 3 = Add Revenue'
        print ' 4 = Remove Revenue'
        print ' 5 = Exit'
        choice = raw_input('Enter your selection:')
        if choice == '1':
            totalBudget = addExpense(totalBudget)
        elif choice == '2':
            totalBudget = removeExpense(totalBudget)
        elif choice == '3':
            totalBudget = addRevenue(totalBudget)
        elif choice == '4':
            totalBudget = removeRevenue(totalBudget)
        elif choice == '5':
            print 'Goodbye!'
        else:
            print '***Invalid entry! Please enter 1-5***'
    
    
#Add expense module
def addExpense(totalBudget):
    bill = int(raw_input('Enter the Expense amount:'))
    manyBill = int(raw_input('Enter the frequency of the Expense per month:'))
    totalBill = bill * manyBill
    totalBudget = totalBudget - totalBill
    checkBudget(totalBudget)
    return totalBudget
#Remove expense module
def removeExpense(totalBudget):
    lessBill = int(raw_input('Enter the amount to remove:'))
    manyLess = int(raw_input('Enter the frequency of the Expense Removal per month:'))
    totalLess = lessBill * manyLess
    if totalLess <= (totalBudget):
        totalBudget = totalBudget + totalLess
        checkBudget(totalBudget)
        
    else:
        print '*ERROR* re-check the amounts entered'
        return totalBudget
#Add Revenue module
def addRevenue(totalBudget):
    income = int(raw_input('Enter the amount of additional income:'))
    totalBudget = totalBudget + income
    checkBudget(totalBudget)
    return totalBudget
#Remove revenue module
def removeRevenue(totalBudget):
    lossincome = int(raw_input('Enter the amount of income to be removed:'))
    totalBudget = totalBudget - lossincome
    checkBudget(totalBudget)
    return totalBudget
#Checks and reports balance
def checkBudget(totalBudget):
    if totalBudget >= (0):
        print 'The remaining budget is: ', totalBudget
    else:
        print 'You have exceeded the monthly budget'
        print 'Re-evaluate your expenses and balance the budget'
        print 'Current balance:', totalBudget
main()



This is the output:

Menu Selection
1 = Add an Expense
2 = Remove an Expense
3 = Add Revenue
4 = Remove Revenue
5 = Exit
Enter your selection:1
Enter the Expense amount:250
Enter the frequency of the Expense per month:15
The remaining budget is: 250
Menu Selection
1 = Add an Expense
2 = Remove an Expense
3 = Add Revenue
4 = Remove Revenue
5 = Exit
Enter your selection:2
Enter the amount to remove:250
Enter the frequency of the Expense Removal per month:7
*ERROR* re-check the amounts entered
Menu Selection
1 = Add an Expense
2 = Remove an Expense
3 = Add Revenue
4 = Remove Revenue
5 = Exit
Enter your selection:5
Goodbye!

This post has been edited by JackOfAllTrades: 19 May 2010 - 05:40 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1