Python - Budget Analysis
I have this code that just keeps looping and need it to stop and display the end part when hitting another key but am not sure how to do that.
userbudget = float( input( "Please enter how much you've budgeted for the month: " ) )
moreexpenses = "y"
usertotalofexpenses = 0
while moreexpenses == "y":
userexpense = float( input( "Enter an expense: " ) )
usertotalofexpenses += userexpense
morexpenses = input( "Do you have more expenses?: Type y for yes, any key for no: " )
if usertotalexpenses > userbudget:
print( "You were over your budget of","$" + format(userbudget, ",.2f"), "by","$" \
+ format( usertotalofexpenses - userbudget, ",.2f" ) )
elif userbudget > usertotalexpenses:
print( "You were under your budget of","$" + format(userbudget, ",.2f"), "by","$" \
+ format( userbudget - usertotalofexpenses, ",.2f" ) )
else:
print ( "You used exactly your budget of","$" + format(userbudget, ",.2f"),"." )