#quote from 'introduction to computation and programming using python, revised edition, MIT'
def findExtremeDivisors(n1, n2):
"""Assumes that n1 and n2 are positive ints
Returns a tuple containing the smallest common
divisor > 1 and the lergest common divisors of n1
and n2"""
minVal, maxVal = None, None
for i in range(2, min(n1, n2) + 1):
if n1%i == 0 and n2%i == 0:
if minVal == None or i < minVal:
minVal = i
if maxVal == None or i > maxVal:
maxVal = i
return (minVal, maxVal)
python multiple assignment demo
最新推荐文章于 2024-11-03 18:46:12 发布