Question: Define a function named main. Ask the user to enter the amount that he or she has budgeted for a month. Example: You have a
Define a function named "main".
Ask the user to enter the amount that he or she has budgeted for a month.
Example: You have a monthly budget of $
You should place other functions under this function so that main can call the main function including the other two functions.
Define a function named "budgetdifference".
A loop should then prompt the user to enter each of his or her expenses for the month and keep a running total.
Example: You spent $ $ $ and $ that month.
Example: The running total will accumulate to $
Calculate the difference between the budget and expenses.
Example: It is under budget. You saved $
For this function, use a sentinel value to control the loop. When the user enters the number zero for the expense, the loop must stop, and calculate the difference.
If your variable name is "expense", you should initialize it with a nonzero value to enter the loop.
You should start the while loop by using this "expense" variable. When this variable is zero, the loop ends. Therefore, the loop continues when this variable is not zero.
You also need an accumulator here to sum all the expenses entered.
Remember today's class exercise. We used "total spent" as an accumulator.
Define a function named "budgetstatus".
When the loop finishes, the program should display the difference between the budget and expenses, and display if it is:
Over budget.
Under budget.
On budget.
You must use fstrings for all the three print functions.
$ sign
Inside the curly brackets, you should type the variable as well as the floating number and digit separator designators.
Indicate if it is over, under, or on budget.
If it is over budget, type "Plan better next time!"
If it is under budget, type "Well done!"
If it is on budget, type "Good planning!"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
