Python Tip Calculator


Why do you put meal = meal + meal * tax

Can’t you put meal = meal * tax

Why would you have to add the meal to itself?


That would equal to just the tax, then, and not the meal + the tax.

The expression on the right hand side is evaluated as,

meal * tax  =>  order of operations precedence

meal + tax on meal

Now we have a new value that includes both the meal price and the tax on the meal, which is now assigned back onto the variable.


Thank you I understand now!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.