def persistence(n):
result = 1
while len(result) != 1 :
n = list(map(int, str(n))
for i in range (len(n)) : # the invalid syntax is apparently here
result = result * n[i]
n = result
return n
print(persistence(123))
Итак, проблема в строке итерации 5.