何らかの理由で、最初のfor...
ループのx変数は、コードを1回繰り返した後にからint
に変わります。str
なぜそうなのか困惑していますが、このスクリプトを実行するたびに、何百ものゼロで構成される文字列がセットに入力されてしまいます。
誰かが興味を持っている場合、これはオイラーの質問4を解決する試みです。
# A palindromic number reads the same both ways.
# The largest palindrome made from the product
# of two 2-digit numbers is 9009 = 91 99.
# Find the largest palindrome made from the product of two 3-digit numbers.
def palindrome():
products = set()
for x in xrange(700,999):
for y in xrange(700,999):
temp = x*y
n = [x for x in str(temp)]
if temp not in products:
if len(n)%2 == 0:
half = len(n)/2
first = n[:half]
last = n[half:]
last.reverse()
if first == last:
products.add(temp)
return products
if __name__ == "__main__":
n = palindrome()
print n