I'm a beginner to Python and am struggling with a project I am working on. The program takes monthly income, fixed monthly expenses, asks for any additional expenses, and then outputs with an if else statement. My issue is in this function:
def spending(income, totals):
finalTotal = income - totals
if income > finalTotal:
print("You saved $", "%.2f"%finalTotal, "this month!")
elif finalTotal > income:
print("You overspent by $", "%.2f"%finalTotal, "this month!")
else:
print("You broke even this month!")
It is printing:
You saved $ -805.00 this month!
When I'd like it to print:
You overspent by $ 805.00 this month!
Any feedback would be greatly appreciated!!
Here is my code: https://replit.com/@ashleyshubin/BudgetProgram#main.py
if/elifconditions), but your formatting is a bit weird in theprintcalls. There's no reason to split the%.2finto its own string just for the formatting. You could use"You saved $%.2f this month!" % finalTotal, or better, do something similar withstr.format(or an f-string).