here is the code:
def main():
totalBudget = 4000
printOptions()
option = input("What would you like to do? ")
while option != 5:
if option == 1:
newExpence = addExpence(totalBudget)
totalBudget = totalBudget - newExpence
printOptions()
option = input("What would you like to do? ")
elif option == 2:
removeExpence = removeExpence(totalBudget)
totalBudget = totalBudget + removedExpence
printOptions()
option = input("What would you like to do? ")
elif option == 3:
newRevenue(totalBudget)
printOptions()
option = input("What would you like to do? ")
elif option == 4:
removeRevenue(totalBudget)
printOptions()
option = input("What would you like to do? ")
else:
print "Input not reconized, please try again"
printOptions()
option = input("What would you like to do? ")
print "Your monthly budget has $",totalBudget,"left"
def printOptions():
print "Press 1 to 'Add a new expence'"
print "Press 2 to 'Remove an expence'"
print "Press 3 to 'Add a new revenue'"
print "Press 4 to 'Remove a revenue'"
print "Press 5 to 'Exit'"
def addExpence(totalBudget):
expence = input("How much is the expence ")
frequency = input("What is the frequency of the expence ")
newExpence = expence * frequency
if newExpence > totalBudget:
print "Sorry, your expence was rejected because the budget has been excided"
newExpence = 0
return newExpence
else:
print "Expence accepted"
return newExpence
def removeExpence(totalBudget):
removedExpence = input("How much is the expence you would like to reomve ")
removedFrequency = input("What is the frequency of the expence to remove ")
removeExpence = removedExpence * removedFrequency
if removeExpence > totalBudget:
print "Please recheck the expence amounts"
removeExpence = 0
return removeExpence
else:
print "The expence has been removed"
return removeExpence
def newRevenue(totalBudget):
print "new"
def removeRevenue(totalBudget):
print "old"
main()
if i choose option 1 the program runs as expected, but with option 2 i get the following error:
Traceback (most recent call last):
File "C:\Python25\personalBudget.py", line 68, in <module>
main()
File "C:\Python25\personalBudget.py", line 12, in main
removeExpence = removeExpence(totalBudget)
UnboundLocalError: local variable 'removeExpence' referenced before assignment
can anyone help me understand the error i get with option 2?