print ("How much does your meal cost")
meal = 0
tip = 0
tax = 0.0675
action = input( "Type amount of meal ")
if action.isdigit():
meal = (action)
print (meal)
tips = input(" type the perentage of tip you want to give ")
if tips.isdigit():
tip = tips
print(tip)
I have written this but I do not know how to get
print(tip)
to be a percentage when someone types a number in.
>>> "{:.1%}".format(0.88)
'88.0%'
Based on your usage of input()
rather than raw_input()
, I assume you are using python3
.
You just need to convert the user input into a floating point number, and divide by 100.
print ("How much does your meal cost")
meal = 0
tip = 0
tax = 0.0675
action = input( "Type amount of meal ")
if action.isdigit():
meal = float(action)
tips = input(" type the perentage of tip you want to give ")
if tips.isdigit():
tip = float(tips) / 100 * meal
print(tip)
It will be
print "Tip = %.2f%%" % (100*float(tip)/meal)
The end %%
prints the percent sign. The number (100*float(tip)/meal)
is what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With