Math operation in Python


Hi there,

Print ( 100 - 25 * 3 % 4 ), the answer is 97, Can some gents explain to me how we get 97 ?, thanks. I know % 4 mean the remainder is 4.


Actually, 3 % 4 means the remainder of 3 ÷ 4. Though, technically, in this case, because of the order of operations, it would actually be 100 - ((25 * 3) % 4). Knowing this, you would just solve the equation by following the order of operations.


@blueriver649, an operator precedence table may be helpful.

The table linked above lists operations to be performed in order from the bottom of the table to the top.


That’s a great resource (as is any documentation) and I’d advise anyone to use it when dealing with more advanced operators. However, if you can remember PEMDAS:

Parenthesis → Exponents → Multiplication / Division → Addition / Subtraction

As well as the fact that % is just another form of division, then you’ve already got the basics of operator precedence memorized.


If worse comes to worse and you are still not sure on how to appropriately dissect a certain math problem, just plug the appropriate numbers and mathematical symbols into your physical calculator or a free online calculator. :+1: or ask again on the forum and we can help point you in the right direction.


Or, better yet, use my favorite online calculator…


Thanks very much , aquaphoenix and other gents . I laughed after this…it is very likely I did not really understand the % sign, the modulus operator.


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