One way to find the greatest common divisor (gcd) of two numbers in Python is to use the math.gcd()
function from the math
module. The math.gcd()
function takes two arguments and returns their gcd.
Here's an example:
main.py112 chars9 lines
Output:
main.py27 chars2 lines
In this example, we import the math
module and assign two numbers, 48
and 60
, to the variables num1
and num2
, respectively. We then use the math.gcd()
function to find their gcd and store the result in the variable gcd
. Finally, we print out the gcd using print()
function. The output indicates that the gcd of 48 and 60 is 12.
gistlibby LogSnag