-
Notifications
You must be signed in to change notification settings - Fork 0
/
e4.py
27 lines (20 loc) · 845 Bytes
/
e4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
#
# Find the largest palindrome made from the product of two 3-digit numbers.
def reverse(num):
return int(str(num)[::-1])
def isPalindrome(num):
if num == reverse(num):
return True
return False
smallest_3_digit_num = 100
largest_3_digit_num = 999
largest_palindrome = 0
for i in range(smallest_3_digit_num,largest_3_digit_num):
for j in range(smallest_3_digit_num, largest_3_digit_num):
num = i * j
if isPalindrome(num):
if num > largest_palindrome:
largest_palindrome = num
print "%d x %d = %d" % (i,j,largest_palindrome)
print "largest palindrome that is a product of two 3 digit numbers is %d" % (largest_palindrome)