Respuesta :
Answer:
The program is written in Python as it possesses a simple and clean syntax.
- def getExpenses():
- total_amount = 0
- amount = float(input("Amount: $"))
- total_amount += amount
- while(amount !=0):
- amount = float(input("Amount: $"))
- total_amount += amount
- return total_amount
- budget = float(input("Enter your monthly budget: $"))
- expenses = getExpenses()
- if(budget > expenses):
- print("Under budget.")
- else:
- print("Over budget.")
Explanation:
Line 1 - 11: (A function to prompt user for each of his/her expenses)
- Create a variable total_amount to track the running total. Assign an initial value zero to the variable. (Line 2)
- Use Python built-in function input() to prompt user for expenses amount and assign the input to variable amount. (Line 4)
- Add the expenses amount to variable total_amount. (Line 5)
- Create a while loop to keep prompting user for expenses amount and add the expenses amount to variable total_amount until user input zero (Line 7-9)
- Return total_amount as output
Line 13: Get user input for monthly budget
Line 14: Call the function getExpenses() to obtain the total expenses from user
Line 16 - 19: Determine if user is over budget or under budget
- Set an if condition - if budget is bigger than expenses, display "Under budget" (Line 17)
- else, display "Over budget" (Line 19)