Calculating Greatest Common Divisor (GCD)

Write a Python program that uses the math module to calculate the greatest common divisor (GCD) of two user input numbers. Return the GCD.

Example 1:

Input: 48, 60
Output: 12

Example 2:

Input: 101, 103
Output: 1

The math module in Python provides a function gcd() that calculates the greatest common divisor of the two numbers.

import math

def calculate_gcd(num1, num2):
    return math.gcd(num1, num2)

print(calculate_gcd(48, 60))  # Output: 12
print(calculate_gcd(101, 103))  # Output: 1

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!