#quote from 'introduction to computation and programming using python, revised edition, MIT'
def findDivisors(n1, n2):
"""Assumes n1 and n2 are positive ints
Returns a tuple containing all common divisions of n1 & n2"""
divisors = () #the empty tuple
for i in range(1, min(n1, n2) + 1):
if n1%i == 0 and n2%i == 0:
divisors = divisors + (i,)
return divisors
divisors = findDivisors(20, 100)
print divisors
tot = 0
for d in divisors:
tot += d
print tot
python tuple demo
最新推荐文章于 2022-04-18 21:34:48 发布