Budget Analysis
Write a program that asks the user to enter the amount that he or she has budgeted for a month. A loop should then prompt the user to enter each of his or her expenses for the month, and keep a running total. When the loop finishes, the program should display the amount that the user is over or under budget.
Budget analysis program code:
#Prompt and read the monthly budget
monthBudget = float(input("Enter amount for your monthly budget: "))
#Initialize the variables
expens= 0
#A loop should then prompt the user to
#enter each of his or her expenses for
#the month, and keep a running total
while True:
expenditureAmount = input("Enter an expense amount(or 'E' to Exist): ")
if expenditureAmount == "E":
break
expens += float(expenditureAmount)
#Calculate the budget
amount = monthBudget - expens
#Display the amount that the user is over or under budge
if amount >= 0:
print("You are under budget by $", amount)
else:
print("You are over budget by $", abs(amount))
Output 1:
Enter amount for your monthly budget: 60000
Enter an expense amount(or 'E' to Exist): 25000
Enter an expense amount(or 'E' to Exist): 3000
Enter an expense amount(or 'E' to Exist): 15000
Enter an expense amount(or 'E' to Exist): E
You are under budget by $ 17000.0
Output 2:
Enter amount for your monthly budget: 50000
Enter an expense amount(or 'E' to Exist): 40000
Enter an expense amount(or 'E' to Exist): 20000
Enter an expense amount(or 'E' to Exist): E
You are over budget by $ 10000.0