#------------------------------------------------------------------------------- # Euclid.py # Find the GCD of two positive integers by Euclid's algorithm # # Try importing Euclid to another program, or into interactive mode. # #------------------------------------------------------------------------------- def GCD(a, b): """ returns the GCD of two positive integers a and b """ r = a%b # print(a, b, r) while r>0: a = b b = r r = a%b # print( a, b, r) return b # end GCD() # function main() ------------------------------------------------------------- def main(): print('Enter two positive integers') a = int(input('First: ')) b = int(input('Second: ')) print( 'GCD('+str(a)+', '+str(b)+') = '+str(GCD(a, b)) ) # end main() # closing conditional --------------------------------------------------------- if __name__=='__main__': main() # end