in the algorithm there is a for that uses the reduction rule 4n +1 times. in the exercise we are allowed to only use the reduction 4n times , is it a mistake ?
Indeed! Thanks for pointing it out. Line 9 in the Python code should say
for iteration in range(4 * n).
4 n iterations are sufficient, but more do not hurt. So the code as it stands now is not wrong.