I suppose we have all heard the meme "learn to code."
A little surprising that a learning platform, such as Moodle, would not be more accommodating for that.
About the only way to post code, on Moodle, is to drop into HTML editing and use the pre and code tags. That really does not look great, and does not work especially well.
I suppose there are other clunky work-arounds, like creating some sort of image file, or video file, and uploading. But it seems there should be something more convenient that that.