160k views
3 votes
Budget Analysis (use while loop) 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.

1 Answer

2 votes

Answer:

print('This program will help you determine whether you\'ve budgeted enough ' +

'for your expenses. You\'ll just need to enter your budget and the ' +

'cost of each of your expenses for the month and we will calculate ' +

'the balance.')

budget = float(input('How much have you budgeted this month? '))

expenses = 0

check = 0

while check >= 0:

check = float(input('Enter an expense amount or -1 to quit: '))

if check != -1:

expenses += check

balance = budget - expenses

if balance < 0:

print('\\You haven\'t budgeted enough. You\'re going to be $', \

format(-1 * balance, ',.2f'), ' short this month.', sep = '')

elif balance == 0:

print('\\Be careful. You\'ve budgeted just enough to make it through ' +

'the month.')

else:

print('\\You will have $', format(balance, ',.2f'), ' extra this month.', \

sep = '')

User Juliensaad
by
6.5k points