Complete the code to compute the remainder when 17 is divided by 5.
result = 17 [1] 5 print(result)
The % operator gives the remainder of division, which is the core of modular arithmetic.
Complete the code to check if 23 is divisible by 7 using modular arithmetic.
if 23 [1] 7 == 0: print("Divisible") else: print("Not divisible")
Using % checks the remainder. If remainder is 0, the number is divisible.
Fix the error in the code to correctly compute (a + b) mod m.
a = 10 b = 15 m = 6 result = (a [1] b) % m print(result)
To add numbers before taking modulo, use the plus operator +.
Fill both blanks to create a dictionary of numbers and their squares modulo 5 for numbers 1 to 5.
squares_mod = {x: (x [1] x) [2] 5 for x in range(1, 6)}
print(squares_mod)Use * to multiply x by itself, then % to take modulo 5.
Fill all three blanks to create a dictionary with keys as numbers squared modulo 7 and values as the original numbers for 1 to 6.
result = [1]: [2] for [3] in range(1, 7)} print(result)
Keys are squares modulo 7 (x**2 % 7), values are original numbers (x), and loop variable is x.