簡単な計算機
from js import document
def calculate():
# 入力値を取得
num1 = float(document.getElementById("num1").value)
num2 = float(document.getElementById("num2").value)
operation = document.getElementById("operation").value
# 演算を実行
if operation == "add":
result = num1 + num2
elif operation == "subtract":
result = num1 - num2
elif operation == "multiply":
result = num1 * num2
elif operation == "divide":
if num2 != 0:
result = num1 / num2
else:
result = "エラー: 0で割ることはできません"
else:
result = "無効な演算"
# 結果を表示
document.getElementById("result").innerHTML = f"計算結果: {result}"