Python Online Compiler
Example: GCD of Two Numbers in Python using Euclidean Algorithm
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# GCD of Two Numbers in Python using Euclidean Algorithm # It's the recursive function to find GCD def gcd(x, y): return y if x == 0 else (x if y == 0 else x if x == y else (gcd(x - y, y) if x > y else gcd(x, y - x))) # It's the driver code p, q = None, None # To store the two positive numbers print ("TWO POSITIVE INTEGER NUMBERS::") p = int (input ()) q = int (input ()) # It will print the final output print ("\nGCD =", gcd(p, q))
295 35
Output
Clear
ADVERTISEMENTS