Does it work if you "paste" that code into a "terminal" in ChatGPT with no context and remove the comments? I suspect it's learning mostly from the fact that you told it what the program does when you asked it to write it.