import math from pyscript import document def bereken(event): output = document.querySelector("#output") try: a = float(document.querySelector("#a").value) b = float(document.querySelector("#b").value) c = float(document.querySelector("#c").value) if a != 1: output.innerText = "Fout: a moet 1 zijn." return d = b**2 - 4*a*c if d < 0: output.innerText = "Geen oplossing mogelijk" return else: x1 = round((-b + math.sqrt(d)) / (2*a),3) x2 = round((-b - math.sqrt(d)) / (2*a),3) def factor(x): if x < 0: return "(x+" + str(abs(x)) + ")" else: return "(x-" + str(x)+")" if d == 0: tekst = ( f"De ontbonden vorm is: {factor(x1)}^2\n" "Gelijk stellen aan 0 geeft:\n" f"{factor(x1)} = 0\n" "Verder oplossen geeft:\n" f"x = {x1}" ) else: tekst = ( f"De ontbonden vorm is: {factor(x1)} {factor(x2)}\n" "Gelijk stellen aan 0 geeft:\n" f"{factor(x1)} = 0\n" f"{factor(x2)} = 0\n" "Verder oplossen geeft:\n" f"x = {x1}\n" f"x = {x2}" ) output.innerText = tekst except ValueError: output.innerText = "Fout: Vul geldige getallen in." def reset(event): reset = document.querySelector("#reset") document.querySelector("#a").value = "" document.querySelector("#b").value = "" document.querySelector("#c").value = "" document.querySelector("#output").innerText = ""