Good grief! What confused‑looking code. Start by writing it out again with all the indentation correct. We have some suggestions about indentation
here. And you can improve your indentation by using a proper
text editor and
writing backwards.
Also where does the magic number 40052 come from? How do you know that is correct?
This looks too difficult for “beginning” so I shall move the discussion.