The Math Module has many functions in Python for mathematical operations. math.gcd()
is a function that gives us the greatest common divisor of two numbers when given.
math.gcd(x,y)
This function accepts two parameters, x
and y
, to calculate the greatest common divisor of two parameters.
This function outputs the greatest common divisor of two numbers that are passed as parameters to the function.
import mathprint(math.gcd(12,15))
In dynamic code, we take the values of the two parameters, using int(input())
, so that we can pass the input as integers to the gcd
function.
Make sure you add the two numbers in the input column below before pressing the run button.
import matha=int(input("Enter your first number:"))b=int(input("Enter your second number:"))print("The greatest common divisor of the two numbers is:",math.gcd(a,b))
Enter the input below