Python in a browser?

The future of web creation is here. While its marketing campaign as a “JavaScript killer” might be a little ambitious at the moment, PyScript makes it possible to run Python in a web browser. Having a little play with it made me realize I needed this more than I thought. I have made a simple Python website that gives you 6 random numbers you could use for the lotto. I call it “UK LOTTO NUMBER PICKER IN PYTHON.” I know, I’m a legend at naming projects! All jokes aside, if you want to use it, the link is: https://stephenwilde.net/lottogen/index.html.


I will not be reviewing PyScript at this stage, as it is still in very early Alpha stages. It’s buggy and not intended for use on production websites (we’ll ignore the fact that I have used it on this website’s sidebar). Not to mention the fact that it has zero documentation yet!


The code I used to make this is below:

<html>
  <head>
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
    <script>
      alert("This entire website was made with Python, CSS & HTML. The only JavaScript is this box you're reading now");
    </script>
  </head>
  <div html>
    <div>
      <title>Lotto number picker | Python</title>
      <body>
        <center> 
          <div class="centered">
            <py-script> 
              import random

              numbers = [
                  random.randrange(1, 59),
                  random.randrange(1, 59),
                  random.randrange(1, 59),
                  random.randrange(1, 59),
                  random.randrange(1, 59),
                  random.randrange(1, 59)
              ]
              numbers.sort()
              print("UK Lotto number picker in Python")
              print("I give you 6 random numbers from 1 to 59 every time you refresh. It's up to you what you play :)")
              print(f'{numbers[0]} :: {numbers[1]} :: {numbers[2]} :: {numbers[3]} :: {numbers[4]} :: {numbers[5]}')
              print("If you win, remember this website's owner, hahaha")
              print(" - ")
              print(" - ")
              print(" - ")
              print("A huge thank you to Py-Script for making this possible")
            </py-script>
          </div>
        </center>
      </body>
    </div>
  </div>
  <style>
    html {
      background-color: #6495ED; 
    }

    .centered {
      position: fixed;
      top: 50%;
      left: 50%;
      font-size: large;
      transform: translate(-50%, -50%);
    }

    div {
      background-color: #00BFFF;
    }
  </style>
</html>