Code viewer for World: Hello Pyscript

// # Clone by Brendan McGrath of:
// # "Python demo (customisable)" by Starter user
// # https://ancientbrain.com/world.php?world=4219533706
// # Please leave this clone trail here.


// The rule for how this API handles Python 'print' output: 
// If we have an element with id="ab-python-console" then 'print' appends to it.
// If such an element does not exist, 'print' writes to the console.

// choose one of:
// <script type="py"> 
// <script type="mpy"> 



document.write(`
  <style>
      #fancy-output {
        font-family: "Fira Mono", "Consolas", monospace;
        color: #2b90d9;
        background: #222;
        padding: 1em;
        border-radius: 8px;
        font-size: 1.2em;
        margin-top: 5em;
        margin-left: 5em;
        white-space: pre;
        box-shadow: 0 2px 8px #0006;
      }
      </style>
  
  <div id="fancy-output"></div>

      <script type="py">
            from pyscript import document
            import math, random
            
            def rainbow_text(text):
                colors = ["#e57373","#f06292","#ba68c8","#64b5f6","#4dd0e1","#81c784","#ffd54f","#ffb74d","#a1887f"]
                return "".join(f'<span style="color:{random.choice(colors)}">{c}</span>' for c in text)
            
            def ascii_art():
                art = [
                    "      .-''''-.",
                    "     /        \\\\",
                    "    /_        _\\\\",
                    "   // \\\\      / \\\\\\\\",
                    "   |\\\\__\\\\    /__/|",
                    "    \\\\    ||    /",
                    "     \\\\        /",
                    "      \\\\  __  /",
                    "       '.__.'",
                    "        |  |"
                ]
                return "<br>".join(art)
            
            message = rainbow_text("✨ Welcome to PyScript! ✨") + "<br><br>" + ascii_art() + "<br><br>" + f'<span style="color:#ffd54f;">π ≈ {math.pi:.8f}</span>'
            document.querySelector("#fancy-output").innerHTML = message
      </script>
`);