(Aug-30-2017, 08:36 AM)hbknjr Wrote: Use:
print('To tip 20% the amount is: $ {:.2f}'.format(tip20))Another way is to use[url=https://docs.python.org/3/library/functions.html#round]round[/url]
.
print('To tip 20% the amount is: $',round(tip20,2))
This was the answer I was looking for!! Thank you so much!!
I used both of your suggestions and they both solved the issue at hand. I was wondering though if there is a certain situation[s] where one option is preferred over the other?
I just wanted to post this to show anyone else that might have this same problem arise.
Here is the code with the new changes, I incorporated both to demonstrate that they both give the same desired result.
Thanks again to HBKNJR, and others for your help!!
food = float(input('What is your food total?: ')) tax = 0.08 * food print('The sales tax is: $ {:.2f}'.format(tax)) total = tax + food print('\nYour total bill comes to: $ {:.2f}'.format(total)) tip10 = 0.10 * total tip15 = 0.15 * total tip20 = 0.20 * total print('\nTo tip 10% the amount is: $ {:.2f}'.format(tip10)) print('To tip 15% the amount is: $',round(tip15,2)) print('To tip 20% the amount is: $',round(tip20,2))And the new and improved output:
Output:What is your food total?: 56.85
The sales tax is: $ 4.55
Your total bill comes to: $ 61.40
To tip 10% the amount is: $ 6.14
To tip 15% the amount is: $ 9.21
To tip 20% the amount is: $ 12.28
>>>
Quote:If you can't learn to do something well?... Learn to enjoy doing it poorly.