166k views
1 vote
Write a python program thast asks the user to enter the budget #amount for the month. A loop should then prompt the user to enter each of his/her #expenses for the month and keep a running total. When finished, the program should #display the amount that the user is over or under budget.

1 Answer

3 votes

Python Code with Explanation:

# get the monthly budget from the user

budget =float(input('Please enter your monthly budget! '))

expense = 0

count = 0

# run a while loop to keep getting input unless user enters -1 to quit

while count >= 0:

count = float(input('Please enter your expenses or enter -1 to quit: '))

if count != -1:

# keep a running total of expenses

expense += count

# when the loop terminates, calculate the monthly balance

balance = budget - expense

# using if elif conditions check for under or over budget

if balance < 0:

print('You are under budget this month! by an amount of: ', balance*-1)

elif balance > 0:

print('You are over budget this month! by an amount of: ', balance)

else:

print('Your budget and expenses are equal this month!')

Output:

Please refer to the attached screenshots!

Write a python program thast asks the user to enter the budget #amount for the month-example-1
Write a python program thast asks the user to enter the budget #amount for the month-example-2
User SMilbz
by
6.5k points