Spaces:
Running
Running
Update index.html
Browse files- index.html +36 -18
index.html
CHANGED
|
@@ -1,19 +1,37 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Pyodide Example</title>
|
| 6 |
+
<script src="https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"></script>
|
| 7 |
+
</head>
|
| 8 |
+
<body>
|
| 9 |
+
<textarea id="python-code" rows="10" cols="50">
|
| 10 |
+
# Sample Python Code
|
| 11 |
+
import math
|
| 12 |
+
|
| 13 |
+
def compute_circle_area(radius):
|
| 14 |
+
return math.pi * radius ** 2
|
| 15 |
+
|
| 16 |
+
print(compute_circle_area(5))
|
| 17 |
+
</textarea>
|
| 18 |
+
<br>
|
| 19 |
+
<button onclick="runPython()">Run Python</button>
|
| 20 |
+
<pre id="output"></pre>
|
| 21 |
+
|
| 22 |
+
<script>
|
| 23 |
+
let pyodideReadyPromise = loadPyodide();
|
| 24 |
+
|
| 25 |
+
async function runPython() {
|
| 26 |
+
await pyodideReadyPromise;
|
| 27 |
+
const code = document.getElementById("python-code").value;
|
| 28 |
+
try {
|
| 29 |
+
let output = await pyodide.runPythonAsync(code);
|
| 30 |
+
document.getElementById("output").textContent = output;
|
| 31 |
+
} catch (err) {
|
| 32 |
+
document.getElementById("output").textContent = err;
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
</script>
|
| 36 |
+
</body>
|
| 37 |
</html>
|