私は、Python(プログラミング)に新たなんだと私はこだわっているが、問題は言う:プロジェクトのpythonとオイラー4:プロジェクトオイラー4の最大の回文製品
「回文数が同じ両方の方法を読み込み、 2つの2桁の数字の積からなる最大の回文桁は、9009 = 91×99です。
3桁の数字の2つの積からなる最大のパリンドロームを探します。
は、ここで私はこれまでのところに来ているものだ:
ProductOfThree = []
ProductOfThreeSTR = []
PalindromicNumber = []
#This first for loop displays all the results possible from the product of two 3 digit Number
for k in range(100, 1000):
for j in range(k, 1000):
Result = k * j
ProductOfThree.append(Result)
#This second loop converts the list of number to a list of string
for i in ProductOfThree:
a = str(i)
ProductOfThreeSTR.append(a)
#The third loop compare the digit of each number of the list to find all the palindromic number of that list
for d in ProductOfThreeSTR:
if len(d) == 6:
if (d[0] == d[5]) and (d[1] == d[4]) and (d[2] == d[3]):
PalindromicNumber.append(d)
elif len(d) == 5:
if (d[0] == d[4]) and (d[1] == d[3]):
PalindromicNumber.append(d)
#And finally here the program display the largest number of the list, which contains only the palindromic numbers
Largest = PalindromicNumber[0]
for p in PalindromicNumber:
if Largest <= p:
Largest = p
print(Largest)
プログラムは、番号99999を表示します。プログラムを再読した後、私は、len(d)== 5のif文が最大の数字を表示したいので役に立たないと分かりました。そして、6桁の数字は常に5桁の数字。プログラムのこの部分を削除した後、私は(906609)持っているはずの結果を持っています。しかし、私たちが5桁の回文数字を見つけようとしていても、リストの最大数を表示するときには無視すべきです、なぜそれが99999の結果を与えるのですか?