Math operation in Python


#1

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.


#2

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.


#3

@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.


#4

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.


#5

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.


#6

Or, better yet, use my favorite online calculator…


#7

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.


#8

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