Translating from python to Mathematica

Hello friends, after researching a long time, I found a file in python that does what I need, unfortunately python know very little of its syntax so I’m wondering if anyone in the community who can help to make a kind of translation of python to mathematica, I can not do alone. Thanks in advance friends

here is the file in python, any idea is welcome, the file is in .txt because I can’t add like .py