用python製作 計算器

2021-10-03 02:20:06 字數 1120 閱讀 9718

複製**後可直接使用

print('-'*25,'我的計算器','-'*25)

def calculator():

result = 0

while true:

try:

s = input("請輸入數字[到0結束]:")

if s == "0":

print("重置輸入n,退出輸入y!")

confirm = input('請選擇[y/n]:')

if confirm in "y, y":

print("最終計算結果:", result)

break

elif confirm in "n, n":

result = 0

print("重置成功,計算結果已歸零.可以開始新的計算了")

continue

else:

print("輸入有誤,返回上層迴圈!")

continue

elif s[0] == "+":

result += float(s[1:])

elif s[0] == "-":

result -= float(s[1:])

elif s[0:2] == "**":

result **= float(s[2:])

elif s[0] == "*":

result *= float(s[1:])

elif s[0:2] == "//":

result //= float(s[2:])

elif s[0] == "/":

result /= float(s[1:])

else:

print("數字前請帶上運算符號+,-,*,/,**,//","如 +16")

print('當前計算結果:', result)

print('-'*61)

except exception as e:

print(e, "輸入有誤,檢查後重新輸入!")

return result

if __name__ == '__main__':

calculator()

python製作稅後工資計算器

介紹 重新實現上乙個挑戰中的個稅計算器,可以計算並處理多人的工資並列印稅後工資。專案需求改變 輸出稅後工資 計算過程需要扣除社會保險費用 支援多人同時計算工資 列印稅後工資列表 個稅計算公式 應納稅所得額 工資金額 各項社會保險費 起徵點 3500元 應納稅額 應納稅所得額 稅率 速算扣除數 其中各...

利用python製作簡單計算器

利用python的定義函式,加上if的條件語句進行程式設計 def add x,y 相加 return x y defsubtract x,y 相減 return x y defmultiply x,y 相乘 return x y defdivide x,y 相除 return x y 使用者輸入 ...

簡易計算器製作

簡易的製作了一下計算器,基本功能都實現了,待後續完善 數字鍵按鈕 private void button8 click object sender,eventargs e 追加 如果下面文字框內容不為0並且上次沒有點選運算子 else 點選了數字按鈕 prev 1 運算子按鈕 private voi...