Friday, September 11, 2026

Python Modulus (%) Mastery Quiz

Python Modulus (%) Mastery Quiz

1. What is the output of the following Python snippet?

x = 17 % 5

print(x)


 * Options: A) 2, B) 3, C) 5, D) 1

 * Answer: A) 2

 * Explanation: 17 divided by 5 is 3 with a remainder of 2 (since 5 × 3 = 15, and 17 - 15 = 2).

2. What is the output of the following Python snippet?

y = 25 % 4

print(y)


 * Options: A) 0, B) 1, C) 2, D) 3

 * Answer: B) 1

 * Explanation: 25 divided by 4 is 6 with a remainder of 1 (since 4 × 6 = 24, and 25 - 24 = 1).

3. What is the output of the following Python snippet?

a = 17 % 5

b = 25 % 4

print(a + b)


 * Options: A) 5, B) 6, C) 3, D) 7

 * Answer: C) 3

 * Explanation: Variable a evaluates to 2 (17 \pmod 5) and variable b evaluates to 1 (25 \pmod 4). Adding them gives 2 + 1 = 3.

4. What is the output of the following Python snippet?

print(10 % 3)


 * Options: A) 0, B) 1, C) 2, D) 3

 * Answer: B) 1

 * Explanation: 10 divided by 3 leaves a remainder of 1 (3 \times 3 = 9, 10 - 9 = 1).

5. What is the output of the following Python snippet?

print(8 % 8)


 * Options: A) 8, B) 1, C) 0, D) 4

 * Answer: C) 0

 * Explanation: When a number is divided evenly by itself, there is no remainder, resulting in 0.

6. What is the output of the following Python snippet?

print(3 % 7)


 * Options: A) 0, B) 3, C) 4, D) 7

 * Answer: B) 3

 * Explanation: When the left operand is smaller than the right operand, the result of the modulo operation is simply the left operand itself.

7. What is the output of the following Python snippet?

print(-17 % 5)


 * Options: A) -2, B) 2, C) 3, D) -3

 * Answer: C) 3

 * Explanation: In Python, the modulo result always takes the sign of the divisor. Since the divisor is positive (5), -17 \pmod 5 yields 3 (5 \times -4 = -20, and -17 - (-20) = 3).

8. What is the output of the following Python snippet?

print(14 % 3 * 2)


 * Options: A) 4, B) 8, C) 6, D) 2

 * Answer: A) 4

 * Explanation: Operators % and * have the same precedence and associate from left to right. First, 14 \pmod 3 = 2, then 2 \times 2 = 4.

9. What is the output of the following Python snippet?

print(20 // 6)


 * Options: A) 3.33, B) 3, C) 4, D) 2

 * Answer: B) 3

 * Explanation: Floor division (//) divides the operands and rounds down to the nearest whole integer. 20 / 6 = 3.333\dots, rounded down to 3.

10. What is the output of the following Python snippet?

print(15 % 4 == 3)


 * Options: A) True, B) False, C) None, D) Error

 * Answer: A) True

 * Explanation: 15 \pmo

d 4 evaluates to 3, and checking equality 3 == 3 results in True.

---------------

**Q1. What does `15 % 4` evaluate to?**

A) 3 ✅

B) 1

C) 4

D) 0

*Answer: A — 4×3=12, 15-12=3*


**Q2. What is the result of `print(20 % 5)`?**

A) 4

B) 1

C) 0 ✅

D) 5

*Answer: C — 5×4=20 exactly, no remainder*


**Q3. Which operator gives the whole-number result of division (ignoring remainder)?**

A) `%`

B) `//` ✅

C) `/`

D) `**`

*Answer: B — floor division drops the remainder*


**Q4. What does `print(17 // 5)` output?**

A) 2

B) 3 ✅

C) 3.4

D) 2.5

*Answer: B — 5 fits into 17 three full times*


**Q5. A number is even if which expression equals 0?**

A) `n // 2`

B) `n % 2` ✅

C) `n / 2`

D) `n ** 2`

*Answer: B — classic even/odd



No comments: