Python實現簡易計算器(巨簡易)

2021-10-14 18:02:33 字數 888 閱讀 1160

while true:

p=input("是否繼續使用計算器?(y/n)")

if p == 'y':

a = float(input("輸入數字1:"))

b = float(input("輸入數字2:"))

c = str(input("輸入運算法則:"))

if c == "+":

z = a + b

print("%s 與 %s 的和為%s"%(a,b,z))

elif c == "-":

z = a - b

print("%s 與 %s 的差為%s"%(a,b,z))

elif c == "*":

z = a * b

print("%s 與 %s 的積為%s"%(a,b,z))

elif c == "/":

z = a / b

print("%s 與 %s 的商為%s"%(a,b,z))

elif c == "%":

z = a % b

print("%s 與 %s 的商的餘數為%s"%(a,b,z))

elif c == "//":

z = a // b

print("%s 與 %s 的商的整數字的值為%s"%(a,b,z))

elif c == "**":

z = a ** b

print("%s 的 %s 次冪為%s"%(a,b,z))

elif p == 'n':

break

else:

print("輸入有誤")

實現簡易計算器

python 剛學python 老師帶著寫了乙個計算器。話不多說直接上 from tkinter import 匯入模組 top tk 設定視窗物件 top.title 計算器 設定視窗標題 v strin ar 接受使用者輸入的字元 v.set 0 設定字元預設值 isopera false 是否...

計算器簡易實現

testdlg.cpp 實現檔案 include stdafx.h include include test.h include testdlg.h include afxdialogex.h ifdef debug define new debug new endif define tag add...

Python 實現簡易計算器功能

效果圖如下 建立橫條型框架 def frame root,side w frame root 在螢幕上建立一塊矩形區域 w.pack side side,expand yes,fill both expand 1時,使能fill屬性 0時,關閉fill屬性 fill both,當gui窗體大小發生變...