總網頁瀏覽量

【 Python學習 】簡易計算機 calculator

num1 = float(input("請輸入第一個數字:"))
op = input("請輸入運算符號(+-*/):")
num2 = float(input("請輸入第二個數字:"))

# 加法
if op == "+":
plus = num1 + num2
print("結果為", plus)
# 減法
elif op == "-":
minus = num1 - num2
print("結果為", minus)
# 乘法
elif op == "*":
multiply = num1 * num2
print("結果為", multiply)
# 除法
elif op == "/":
divide = num1 / num2
print("結果為", divide)
else:
print("您輸入有誤,無法計算!")


請輸入第一個數字:9
請輸入運算符號(+-*/):*
請輸入第二個數字:5.5
結果為 49.5

沒有留言:

張貼留言

2026必勝客超值優惠代碼組合,享受美食就看這邊

94103四小福雙拼系列$199 13吋大比薩,雙拼-四小福+照燒雞 或 四小福+熱帶鳳梨海鮮總匯1個。 平日外帶限定-94199超值單點大比薩$199 13吋大比薩1個,7種超值口味-蒜香起司燻雞培根、義式培根黃金薯等任選。 平日外帶限定-94299人氣單點大比薩$299 13...