An example of using Brython to embed Python in an HTML script tag, scroll down for the source code. (You can also press F12 or right-click -> Inspect to view the full page source, but the Python code will be minified.)


Enter a positive number:



Prime Number:

Optimus Prime

Code highlighed with Pygments:

import browser, math

def check_prime(num):
    num = int(num)
    for i in range(2, math.ceil(math.sqrt(num))):
        if num % i == 0:
            return False
    return True

def on_submit(event):
    number = browser.document["user_input"].value
    browser.console.log(number)
    browser.document["output"].html = "Prime Number: " + str(check_prime(number))

browser.document["submit-button"].bind("click", on_submit)