tuple DEMO

来源:互联网 发布:数控车床编程自学网 编辑:程序博客网 时间:2024/05/23 01:21
#quote from MIT 'introduction to computation and programming using python, Revised'def findDivisors(n1, n2):    """Assumes that n1 and n2 are positive ints       Returns a tuple containing all common divisors 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 += (i,)    return divisors    divisors = findDivisors(20, 100)print divisorstotal = 0for d in divisors:    total += dprint total


%run "C:\Users\Administrator\test.py"
(1, 2, 4, 5, 10, 20)
42

0 0