from pyscript import document import math def lees_getal(id_naam): waarde = document.getElementById(id_naam).value.strip() if waarde == "": return None return float(waarde) def bereken(event): antwoord = document.getElementById("antwoord") zijde = document.getElementById("zijde").value.lower() try: a = lees_getal("inputA") b = lees_getal("inputB") c = lees_getal("inputC") except ValueError: antwoord.innerText = "Vul alleen geldige getallen in." return if zijde == "": antwoord.innerText = "Kies eerst welke zijde je wilt berekenen." return if zijde == "c": if a is None or b is None: antwoord.innerText = "Vul A en B in om C te berekenen." return if a <= 0 or b <= 0: antwoord.innerText = "Lengtes moeten groter zijn dan 0." return uitkomst = math.sqrt(a**2 + b**2) antwoord.innerText = f"C = {uitkomst}" elif zijde == "a": if b is None or c is None: antwoord.innerText = "Vul B en C in om A te berekenen." return if b <= 0 or c <= 0: antwoord.innerText = "Lengtes moeten groter zijn dan 0." return if c <= b: antwoord.innerText = "C moet groter zijn dan B, omdat C de schuine zijde is." return uitkomst = math.sqrt(c**2 - b**2) antwoord.innerText = f"A = {uitkomst}" elif zijde == "b": if a is None or c is None: antwoord.innerText = "Vul A en C in om B te berekenen." return if a <= 0 or c <= 0: antwoord.innerText = "Lengtes moeten groter zijn dan 0." return if c <= a: antwoord.innerText = "C moet groter zijn dan A, omdat C de schuine zijde is." return uitkomst = math.sqrt(c**2 - a**2) antwoord.innerText = f"B = {uitkomst}" else: antwoord.innerText = "Kies A, B of C."