jeudi 1 novembre 2018

Python - long halt while calculating palindrome number

I'm trying to find largest palindromic number made from the product of two 3-digit numbers with my code. it works fine for 2-digit and 3-digit, but when I try it with 4-digit numbers, it doesn't work anymore. There is no output or "Process finished with exit code 0" at the end. It just halted like it was in an infinite loop.

palin = 0
for x in range(1, 10000):
    for y in range(1, 10000):
        mult = x * y

    if str(mult) == str(mult)[::-1]:
        if mult > palin:
            palin = mult

print(palin)

where did I go wrong? I just started Python about a month ago, so my code is still not effective

Aucun commentaire:

Enregistrer un commentaire