#! /usr/bin/env python """ gcd.py calculates the greatest common divisor g(m,n) of two nonnegative integers m and n using Euclid prescription. Greatest Common Divisor Euclid's prescription: g(m,n) = m if n =0 else g(m,n) = g(n, m mod n) Using input values of 108 and 192 the result g(108, 180) is found to be 36 Paul Eugenio PHZ4151C Jan 25, 2019 """ from __future__ import division, print_function def g(m,n): """ Calculates the greatest common divisor g(m,n) of two nonnegative integers m and n using Euclid prescription. The proceedure utilizes recursive methods. Values of m & n must both be nonnegative integers """ if n == 0: return m elif m >= 0 and n > 0: return g(n, m%n ) else: return "error: g(m,n) use of negative number(s)" m = abs(int(raw_input("Enter a nonnegative integer: "))) n = abs(int(raw_input("Enter another nonnegative integer: "))) print("The greatest common divisor of ",m , " and ", n, " is ",g(m,n),".", sep='' )