您的位置:首页 > 产品设计 > UI/UE

sequence DEMO(tuple or string)

2015-07-09 10:04 483 查看
#quote from MIT 'introduction to computation and programming using python, Revised'
def findExtremeDivisors(n1, n2):
"""Assumes that n1 and n2 are positive ints
Returns a tuple containing the smallest common
divisor > 1 and the largest common divisor 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)

minDivisor, maxDivisor = findExtremeDivisors(100, 200)
print minDivisor, maxDivisor


%run "C:\Users\Administrator\test.py"

2 100
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: