#Find the largest palindrome made from the product of two 3-digit numbers.
from sys import exit
rev=0
print ' let us start'
for i in range(999,100,-1):
for j in range(999,100,-1):
product = i*j
temp = product
rev1 = str(product)[::-1]
a = rev1
if temp == a:
print ' is a palindrome'
if a > rev:
rev = a
c = temp
h = i
y = j
print '%r*%r=%r,which is the highest palindrome %r' % ( h, y, c, rev)
print a
print rev1
print temp
print 'over'
出力:私はエディターとして崇高なtext2を使用しています
let us start
Traceback (most recent call last):
File "palindrome.py", line 19, in <module>
print '%r*%r=%r,which is the hghest palindrome %r' % ( h, y, c, l)
NameError: name 'h' is not defined
n == a
(つまり)は文字列であり、つまりは整数True
であるため、は決してなりません。試してみてください:k = str(t)[::-1]
a
t = i*j
n
a = int(k)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加