I think you may want to use strings in those input statements:
x = float(input("What is/was the cost of the meal?"))
In addition, it may be a good idea to use {0}
in your format strings (rather than {}
), at least if you want to keep compatible with pre-2.7 Python (although in that case, I'd probably be using raw_input
as well). Even after 2.7, I still prefer the positional specifiers since it makes it clearer for me.
This code works fine for me:
x = float(input("What is/was the cost of the meal?"))
y = float(input("What is/was the sales tax?"))
z = float(input("What percentage tip would you like to leave?"))
print ("Original Food Charge: ${0}".format(x))
print ("Sales Tax: ${0}".format(y*x))
print ("Tip: ${0}".format(x*z))
print ("Total Charge For Food: ${0}".format(x+(y*x)+(z*x)))
such as with:
What is/was the cost of the meal?50
What is/was the sales tax?.05
What percentage tip would you like to leave?.1
Original Food Charge: $50.0
Sales Tax: $2.5
Tip: $5.0
Total Charge For Food: $57.5
Though you may want to make it clear that the "percentages" should be in fractional format, lest entering 20 as your tip will make the waiter/waitress very happy.
Or, you can divide y
and z
by 100 to turn them from percentages to fractions.