File size: 1,009 Bytes
0b9b881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29d65cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Pyodide Example</title>
    <script src="https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"></script>
</head>
<body>
    <textarea id="python-code" rows="10" cols="50">
# Sample Python Code
import math

def compute_circle_area(radius):
    return math.pi * radius ** 2

print(compute_circle_area(5))
    </textarea>
    <br>
    <button onclick="runPython()">Run Python</button>
    <pre id="output"></pre>

    <script>
        let pyodideReadyPromise = loadPyodide();

        async function runPython() {
            await pyodideReadyPromise;
            const code = document.getElementById("python-code").value;
            try {
                let output = await pyodide.runPythonAsync(code);
                document.getElementById("output").textContent = output;
            } catch (err) {
                document.getElementById("output").textContent = err;
            }
        }
    </script>
</body>
</html>