乙個極簡單的計算器

2022-02-23 23:59:02 字數 814 閱讀 9481

網上看到的計算器程式,再加上一些對於=號的處理,就完美了,例如輸入:3+6*8敲回車,立刻就列印出51,如果輸入3+6*8=則出錯,這兒需處理一下.

import os

while true:

dynamic = input('輸入計算表示式:')

if dynamic != 'cls':

try:

result = eval(dynamic)

print('計算結果:'+str(result))

except:

print('計算表示式輸入有誤!')

else:

command = 'cls'

os.system(command)

稍微修改一下,解決處理=號的問題

import os

while true:

dynamic = input('輸入計算表示式:')

if dynamic != 'cls':

try:

result = eval(dynamic.lstrip().rstrip("="))

print('計算結果:'+str(result))

except:

print('計算表示式輸入有誤!')

else:

command = 'cls'

os.system(command)

乙個簡單的計算器

乙個非常簡單的計算器 來自sololearn 只能進行單一計算 while true print 設定 print enter 增加 to 增加 two numbers print enter 減去 to 減去 two numbers print enter 相乘 to 相乘 two numbers...

製作乙個簡單的計算器

coding utf 8 time 2020 2 5 author wowilliam210 file calculator.py software pycharm import win32com.client class acalculator object def check num zsq f...

QT實現乙個簡單的計算器

最近幾天在學習qt,在了解了訊號和槽機制 布局管理 還有一些控制項的使用後,便試著寫了乙個計算器,帶自定義的快捷鍵,剪貼簿 複製和貼上 的操作,有 選單欄 選擇 裡的功能還未實現,等啥時候有時間把它補上吧。還有許多不足和需要修改的地方,希望各位大牛能幫忙指出其中的問題,謝謝。下面就貼出我的 calc...