ChatterBank5 mins ago
Python - Budget Analysis
1 Answers
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"),"." )
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"),"." )
Answers
Best Answer
No best answer has yet been selected by britterbean74. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.Related Questions
Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.