How to find the largest palindrome made from the product of two 4-digit numbers in Python

1 Answer

0 votes
def is_palindrome(number):
    return str(number) == str(number)[::-1]

largest_palindrome = 0

# range(start, stop, step) 

for num1 in range(9999, 999, -1):
    for num2 in range(num1, 999, -1):
        product = num1 * num2
        if product > largest_palindrome and is_palindrome(product):
            largest_palindrome = product
            
print(largest_palindrome)


    
'''
run:
    
99000099

'''

 



answered Oct 15, 2023 by avibootz
...