For context, this code is written on a video within the channel Numberphile by Matt Parker talking about multiplication persistence. The code is written in Python 2, and my question is about the line return "DONE"
.
Evidently, this prevents an infinite loop from being generated, as it is clear running an example (below) with and without that line:
def per(n, steps = 0):
if len(str(n)) == 1:
print "TOTAL STEPS " + str(steps)
return "DONE"
steps += 1
digits = [int(i) for i in str(n)]
result = 1
for j in digits:
result *= j
print result
per (result, steps)
per(27)
# 14
# 4
# TOTAL STEPS 2
Now, the same code without the line return "DONE"
would not end the loop, and yield:
14
4
TOTAL STEPS 2
4
TOTAL STEPS 3
4
TOTAL STEPS 4
4
TOTAL STEPS 5
4
TOTAL STEPS 6
4
TOTAL STEPS 7
4
TOTAL STEPS 8
4
TOTAL STEPS 9
4
TOTAL STEPS 10
4
TOTAL STEPS 11
4
TOTAL STEPS 12
4
TOTAL STEPS 13
4
TOTAL STEPS 14
4
...
My question is about the meaning of 'return "HOME"'. Does it simply mean STOP. Is there any meaning of "HOME" in there?