find the largest three-digit number equal to the square of the product of its digits in python

To solve this problem, we need to iterate through all the three-digit numbers and check if the square of the product of its digits is equal to the number itself. We can do this using nested loops.

main.py
largest_num = 0

for i in range(100, 1000):
    product = 1
    for digit in str(i):
        product *= int(digit)
    if product**2 == i:
        largest_num = i

print(largest_num)
183 chars
11 lines

We start the outer loop from 100 and go up to 999 since we are looking for three-digit numbers. We then calculate the product of the digits using the inner loop, which iterates over each digit of the current number. We then check if the square of the product is equal to the number itself and update the largest_num variable accordingly. Finally, we print the largest three-digit number that satisfies the condition.

gistlibby LogSnag