This forum is now read-only. Please use our new forums! Go to forums
So it works, but how/why?
meal = 44.50
tax = 0.0675
tip = 0.15
meal += meal * tax
total = meal + meal * tip
print("%.2f" % total)
shouldnt
total = meal + meal * tip
be equal to (47.50375 + 47.50375 * 0.15) = 14.251125 ?
how does it work?
Also: What the hell does the last line of code do?
Answer 54a1835776b8fef4480142bf
Answer 54a45de151b8872850000388
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
4 comments
Total should be 47.50 + 47.50 * 0.15 ?
Order of operations. In math u do Multiplications before the addition. So the computer does it the same way. In that line u just add the tax value to the meal value.
I’m still not getting why meal + meal * tax is necessary over meal * tax, any takers? I understand it’s right, just not why, which will trip me up eventually,,,
meal * tax gives you the value of the tax (44.50 * .15 = 6.675). the extra meal is to add the value of the meal back to the bill. 6.675 + meal