How to run Python in HTML using PyScript?

Before knowing about running the Pyscript, first we need to know what is pyscript. I have written a separate article kindly check that one if you wish am leaving the link here.

PyScript has three main components for writing python in HTML.

  • py-env defines the Python packages needed to run your Python code. 
  • py-script is where you write your Python code that gets executed within the web page.
  • py-repl creates a REPL (read-eval-print loop) component that evaluates the code users enter and displays the results.
1.Create a HTML file.
2. Go to https://pyscript.net/ website.
3. Click on install. Copy the code and paste it on the <head> tag of the HTML file.
pyscript website
4. Use PyScript tags to run python code.
sample code

OUTPUT:

output
References:
  1. https://anaconda.cloud/pyscript-python-in-the-browser
  2. https://pyscript.net/