javascript-python / index.html
admin08077's picture
Update index.html
0b9b881 verified
<!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>