def search(limit): maxi = [0, 0, 0] for x in range(1, limit + 1): num = 1 for y in range(limit): num *= x s = sum(map(lambda x: int(x), str(num))) if s > maxi[0]: maxi = [s, x, y + 1] return maxi print(search(100))