Python Tip Calculator


#1

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?


#2

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.


#3

Thank you I understand now!


#5

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