0
0
DSA Pythonprogramming~10 mins

Modular Arithmetic Basics in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compute the remainder when 17 is divided by 5.

DSA Python
result = 17 [1] 5
print(result)
Drag options to blanks, or click blank then click option'
A%
B//
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using // instead of % returns the quotient, not remainder.
2fill in blank
medium

Complete the code to check if 23 is divisible by 7 using modular arithmetic.

DSA Python
if 23 [1] 7 == 0:
    print("Divisible")
else:
    print("Not divisible")
Drag options to blanks, or click blank then click option'
A//
B%
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using // returns quotient, not remainder.
3fill in blank
hard

Fix the error in the code to correctly compute (a + b) mod m.

DSA Python
a = 10
b = 15
m = 6
result = (a [1] b) % m
print(result)
Drag options to blanks, or click blank then click option'
A*
B-
C+
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using - or * changes the operation meaning.
4fill in blank
hard

Fill both blanks to create a dictionary of numbers and their squares modulo 5 for numbers 1 to 5.

DSA Python
squares_mod = {x: (x [1] x) [2] 5 for x in range(1, 6)}
print(squares_mod)
Drag options to blanks, or click blank then click option'
A*
B+
C%
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * changes the operation.
5fill in blank
hard

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.

DSA Python
result = [1]: [2] for [3] in range(1, 7)}
print(result)
Drag options to blanks, or click blank then click option'
Ax**2 % 7
Bx
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.