0

Hi,

I'm trying to use the built in gcd method to calculate the gcd for two values. Unfortunately I can't seem to import the right module to get the method.

from fractions import Fraction
...
x = gcd(a,b)
2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by kenji
0

Here you go:

# tested with Python 3.1.1

import fractions

a = 10
b = 25
cd = fractions.gcd(a, b)

sf = "the greatest common divisor of the integers %d and %d is %d"
print( sf % (a, b, cd) )

"""my result
the greatest common divisor of the integers 10 and 25 is 5
"""
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.