The modulo in Python is confusing.
In Python, %
operator is calculating the remainder:
>>> 9 % 5
4
However:
>>> -9 % 5
1
Why is the result 1
? and not -4
?
The notation Z for the set of integers comes from the German word Zahlen, which means "numbers". Integers strictly larger than zero are positive integers and integers strictly less than zero are negative integers.
Integer Symbol The letter (Z) is the symbol used to represent integers. An integer can be 0, a positive number to infinity, or a negative number to negative infinity. One of the numbers …, -2, -1, 0, 1, 2, …. The set of integers forms a ring that is denoted Z.
The numbers m and n are integers.
How many pairs of positive integers m,n satisfy 1/m + 4/n = 1/12, where n is an odd integer less than 60? Thus n take only three values– 49, 51 and 57. Hence there are three pairs of (m,n) which satisfy the given conditions.
Because in python, the sign matches the denominator.
>>> 9 % -5
-1
>>> -9 % 5
1
For an explanation of why it was implemented this way, read the blog post by Guido.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With