#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. a = 999 b = 999 def flipNumber (number): flipped = "" strNumber = str(number) for i in range(len(strNumber)): flipped += strNumber[len(strNumber) -i -1] return flipped def testPalindrome (candidate): flipped = flipNumber(int(candidate)) for i in range(len(candidate)/2): if flipped[i] != candidate[i]: return False return True a = 999 b = 999 biggestPalindrome = 0 while b > 0: while (testPalindrome(str(a*b)) != True): b -= 1 if a*b > biggestPalindrome: biggestPalindrome = a*b a = 999 print "biggestPalindrome = " + str(biggestPalindrome)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question