Can the result of a modulo operation be larger than the divisor?

Question

In the context of this exercise, can the result of a modulo operation be larger than the divisor?

Answer

No, the result of a modulo operation can never be larger than the divisor, assuming all positive values being used in the operation. If the division is done correctly, then the divisor was fitted into the dividend as many times as possible. If the remainder is larger than the divisor, then this means the divisor could still be fitted into the dividend, so that means the division was not done correctly.

Explanation

"""
Take for example
10 % 3

Dividend: 10
Divisor: 3

We divide the divisor into the dividend as many times as possible, 
until we cannot fit it into the dividend any more.
10 >= 3 * 1
10 >= 3 * 2
10 >= 3 * 3
10 < 3 * 4 # Stop at the previous.

We stop at 3 * 3 because the 3 * 4 does not fit into 10 anymore. 

We then take the remainder of this,
10 – 3 * 3 = 1

Therefore the remainder is 1, which is less than the divisor, 3.
"""

The only way that the remainder would be greater than the divisor would be if we stopped at 3 * 2 or earlier, which would have been incorrect.

18 Likes

Hello!

Can I assign the calculation of the modulo directly to the variable like the below:
my_team = print ( 27%4)
The result is again 3, however it isn’t correct as per the lesson goals.

1 Like

That’ll because you’re passing the calculation 27 % 4 to print and assigning the output of print to my_team. The print function isn’t designed for returning anything so you wind up assigning the None object to my_team instead. Just use the equation you have without print and assign that for the behaviour you expected.

3 Likes

Thank you! @jephos249 this was helpful.

1 Like

can someone help me ot with this question I cant undersrtanding
Based on the value of order_263_r , should this order receive a coupon? Create a new variable called order_263_coupon and assign to it a value of "yes" if the order should get a coupon, otherwise "no" .

1 Like

order_263_r = 263 % 11

print(order_263_r)

order_263_coupon = “no”

print(order_263_coupon)

order_264_r = 264 % 11

print(order_264_r)

order_264_coupon = “yes”

print(order_264_coupon)