Donate SIGN UP

Python - Budget Analysis

Avatar Image
britterbean74 | 00:06 Wed 31st May 2017 | Gaming
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"),"." )
Gravatar

Answers

Only 1 answerrss feed

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.
In Python, all the statements indented by the same number of character spaces after a programming construct are considered to be part of a single block of code.
I'm guessing there's a problem with your indentation.

Only 1 answerrss feed

Do you know the answer?

Python - Budget Analysis

Answer Question >>

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.