#------------------------------------------------------------------------------- # 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 # main program ---------------------------------------------------------------- # This conditional statement allows us to import Euclid.py as a module without # running the main program. if __name__=='__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 if