In this tutorial @Taifun develops a tutorial to run Python code using Skulpt. Thank you @Taifun!
We're going to try it.
I'm going to simplify the Skulpt code and the block code a bit, here they are.
skulpt.htm
<script src="jquery-1.9.0.min.js"></script>
<script src="skulpt.min.js"></script>
<script src="skulpt-stdlib.js"></script>
<script>
function builtinRead(x) {
if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
throw "File not found: '" + x + "'";
return Sk.builtinFiles["files"][x];
}
function outf(text) {
window.AppInventor.setWebViewString("" + text);
}
var prog = window.AppInventor.getWebViewString();
Sk.configure({output:outf, read:builtinRead});
try {
Sk.importMainWithBody("<stdin>",false,prog);
} catch (e) {
alert(e);
}
</script>
pitagoras.py
import math
cateto1 = input("Valor de un cateto: ")
cateto2 = input("Valor del otro cateto: ")
hipotenusa = math.sqrt(math.pow(int(cateto1),2) + math.pow(int(cateto2),2))
print(hipotenusa)
p170A_pythonpitagoras.aia (151.0 KB)
There are still lots of things to implement under the hood, but we have made a huge leap forward in Python 3 compatibility. We will still support Python 2 as an option going forward for projects that rely on it. from https://skulpt.org/
You can try the Python code at: