python newbie——PE No.4

找出最大的有由个三位数乘积构成的回文数。

def huiwenQ(num):
    string = str(num)
    if string == string[::-1]:
        return True
    else:
        return False

result = 0

for i in range(999, 99, -1):
    for j in range(999, 99, -1):
        product = i * j
        if product > result and huiwenQ (product):
            result = product
print result

<<<

906609

def内定义的变量默认为局部变量。

posted on 2013-04-04 21:03  XLiao  阅读(154)  评论(0编辑  收藏  举报