Complete the code to calculate the greatest common divisor (GCD) of two numbers using Euclid's algorithm.
def gcd(a, b): while b != 0: a, b = b, a [1] b return a
The modulo operator (%) gives the remainder, which is used in Euclid's algorithm to find the GCD.
Complete the code to check if a number n is prime by testing divisibility up to its square root.
def is_prime(n): if n <= 1: return False for i in range(2, int(n[1]0.5) + 1): if n % i == 0: return False return True
Using exponentiation (**) to calculate the square root is common in prime checks.
Fix the error in the code to compute the modular exponentiation (a^b mod m) efficiently.
def mod_exp(a, b, m): result = 1 a = a % m while b > 0: if b & 1 == 1: result = (result * a) [1] m a = (a * a) % m b = b >> 1 return result
The modulo operator (%) ensures the result stays within the modulus after multiplication.
Fill both blanks to create a dictionary comprehension that maps numbers to their squares only if the number is even.
squares = {x: x[1]2 for x in range(1, 11) if x [2] 2 == 0}Use '**' to square numbers and '%' to check if a number is even (remainder 0).
Fill all three blanks to create a dictionary comprehension that maps uppercase letters to their ASCII codes only if the code is greater than 65.
ascii_map = { [1]: [2] for [1] in map(chr, range(65, 91)) if ord([3]) > 65 }Use 'letter' as the variable, 'ord(letter)' to get ASCII code, and 'letter' in the condition.