please modify the html code below so that user can upload or paste a photo on the page and perform OCR function. Please test the code before providing your result.
Math operations
import math
print(f"Square root of 16: {math.sqrt(16)}")
List operations
numbers = [1, 2, 3, 4, 5]
squared = [x**2 for x in numbers]
print("Squared numbers:", squared)
Run Python Code
Clear Output
Loading Python environment...
<script>
let pyodide;
async function main() {
try {
pyodide = await loadPyodide();
document.getElementById('output').innerHTML = 'Python environment ready!';
document.getElementById('runBtn').disabled = false;
} catch (error) {
document.getElementById('output').innerHTML = `Error loading Pyodide: ${error}`;
}
}
async function runPython() {
if (!pyodide) {
document.getElementById('output').innerHTML = 'Python environment not ready yet!';
return;
}
const code = document.getElementById('code').value;
const output = document.getElementById('output');
try {
// Capture stdout
pyodide.runPython(`
import sys
from io import StringIO
Redirect stdout to capture print statements
old_stdout = sys.stdout
sys.stdout = StringIO()
`);
// Run user code
pyodide.runPython(code);
// Get captured output
const result = pyodide.runPython(`
captured_output = sys.stdout.getvalue()
sys.stdout = old_stdout
captured_output
`);
output.innerHTML = result || 'Code executed successfully (no output)';
} catch (error) {
output.innerHTML = `Error: ${error}`;
}
}
function clearOutput() {
document.getElementById('output').innerHTML = '';
}
// Initialize when page loads
document.getElementById('runBtn').disabled = true;
main();
</script>