Blake Rayfield Ph.D.
Northern Arizona University
<!DOCTYPE html>
<html lang="en">
<head>
<title>Simple Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="https://pyscript.net/releases/2023.03.1/pyscript.css" />
<script defer src="https://pyscript.net/releases/2023.03.1/pyscript.js"></script>
</head>
<body>
<py-script src=./main.py></py-script>
<h2>Solve this simple math problem</h2>
<div id='problem'></div>
<input id='student-answer'>
<button id='submit-answer' py-click="check_answer()" class='py-button'>Submit Answer</button>
<div id='answer'></div>
</body>
</html>#### main.py ####
import random
from pyscript import Element
r1 = random.randint(3, 9)
r2 = random.randint(3, 9)
SignOptions = ["+","-"]
sign_ = random.choice(SignOptions)
display(str(r1) + " " + sign_ + " " + str(r2) + " =", target='problem', append='True')
def check_answer():
evaluation = Element("problem").innerHtml
evaluation = evaluation.replace("<div>","")
evaluation = evaluation.replace("</div>","")
evaluation = evaluation.replace("=","")
response_ = Element("student-answer").value
if str(eval(evaluation)) == str(response_):
Element("answer").write("Great Job!!!")
else:
Element("answer").write("Try Again")
Notebooks are great when students have or you want students to have a programming background.
However, notebooks don’t let the content take the lead. PyScript seems to be a happy medium where you can push the content, while having the ability to change the code.
Bottom line, we don't always want students to have to confront the code.