import math from pyscript import document def bereken(event): output = document.querySelector("#output") try: x1 = float(document.querySelector("#x1").value) x2 = float(document.querySelector("#x2").value) y1 = float(document.querySelector("#y1").value) y2 = float(document.querySelector("#y2").value) if x1 == x2: output.innerText = "x1 en x2 mogen niet gelijk zijn" return a = (y2 - y1) / (x2 - x1) b = y1 - a * x1 if b < 0: output.innerText = f"De formule is: y = {round(a,3)}x - {round(abs(b),3)}" else: output.innerText = f"De formule is: y = {round(a,3)}x + {round(b,3)}" except ValueError: output.innerText = "Fout: Vul geldige getallen in." def reset(event): document.getElementById("x1").value = "" document.getElementById("x2").value = "" document.getElementById("y1").value = "" document.getElementById("y2").value = "" document.getElementById("output").innerText = ""