The code in the pdf is python2. You can try to use 2to3 tool to try to convert it to python3. I see you try to solve some of the issues, like print, but you don't need to import xrange from
As a side note - it's dishonest to claim you are author of the code, given it's not true.
mpmath.libmp.backend
. in python3 xrange becomes range and 2to3 tool will fix it.As a side note - it's dishonest to claim you are author of the code, given it's not true.