#WSQ12

Greatest Common Divisor

The function should receive two integers and return an integer.Obviously you should test your function, so create a main program that asks the user for two values, calculates the gcd and displays that.

def gcd(x,y):
    if (x==y):
        ans=x
    else:
        if(x>y):
            ans=gcd((x-y),y)
        else:
            ans=gcd(x,(y-x))
    return ans

x=int(input(“Give me the first number: “))
y=int(input(“Give me the second number: “))
agcd= gcd(x,y)
print(“the Greatest Common Divisor of “,x,” and “,y,” is: “,agcd)

CC BY 4.0 #WSQ12 by Luis Vargas is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.