Welcome, guest | Sign In | My Account | Store | Cart

Calculate the Greatest common divisor from two numbers

Python, 7 lines
1
2
3
4
5
6
7
def mcd(a,b):
    r=a
    while (r):
        r=a%b; a=b; b=r 
    return a   

print mcd(120,95)

2 comments

WIlbur Severny 9 years, 6 months ago  # | flag

from fractions import gcd gcd(120,95)

juan (author) 9 years, 6 months ago  # | flag

Wilbur thanks,

Created by juan on Fri, 19 Sep 2014 (MIT)
Python recipes (4591)
juan's recipes (6)

Required Modules

Other Information and Tasks