日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python计算器函数图像_Python图形计算器,python,图像,化

發布時間:2023/12/10 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python计算器函数图像_Python图形计算器,python,图像,化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用python實現簡單計算器

本文目錄

1.功能目標

2.解題思路

3.關鍵函數說明

4.界面以及結果展示

一.功能目標

用戶選擇不同的功能實現不同的計算結果

1.標準計算

用戶輸入+, -, *, /,pow,sqrt等不同的按鈕進行不同的計算

2.解方程運算

用戶根據提示格式輸入方程參數

a.解二元一次方程

b.解三元一次方程

c.解一元二次方程

d.解一元三次方程

二.解題思路

1.判斷按下的數字按鍵還是功能按鍵,需要一個值進行判斷

2.可以使用eval函數進行標準運算

3.使用sympy模塊進行方程的解運算

eval函數參考:

https://www.runoob.com/python/python-func-eval.html

sypmy模塊的使用參考:

https://blog.csdn.net/weixin_34352005/article/details/92949596#%E4%B8%80%E6%B1%82%E8%A7%A3%E5%A4%9A%E5%85%83%E4%B8%80%E6%AC%A1%E6%96%B9%E7%A8%8B-solve

本文參考了此文章的實現:

https://blog.csdn.net/cui_yonghua/article/details/104129520?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

三.關鍵函數說明

開方運算

def f_sqrt(self):

strnum = float(self.result.get())

endnum = math.sqrt(strnum)

self.result.set(str(endnum))

if self.lists != 0:

self.ispresssign = True

self.lists.clear()

冪運算

def f_pow(self):

num_one = float(self.lists.pop())

num_two = float(self.result.get())

self.ispresssign = True

value = math.pow(num_one, num_two)

self.result.set(str(format(value, '.6f')))

self.lists.clear()

解方程的幾個函數都使用float類型

解二元一次方程

用sympy模塊的solve方法實現

def t_count(self):

aone = float(self.entry_a1.get())

bone = float(self.entry_b1.get())

cone = float(self.entry_c1.get())

atwo = float(self.entry_a2.get())

btwo = float(self.entry_b2.get())

ctwo = float(self.entry_c2.get())

x = sy.Symbol('x')

y = sy.Symbol('y')

t_result = sy.solve([aone*x + -1*cone + bone*y, atwo*x + -1*ctwo + btwo*y])

if x in t_result and y in t_result:

self.result_x.set(t_result[x])

self.result_y.set(t_result[y])

elif x in t_result or y in t_result:

self.result_x.set('無唯一解')

self.result_y.set('無唯一解')

else:

self.result_x.set('無解')

self.result_y.set('無解')

解三元一次方程與二元一次方程類似

def f_count_two(self):

aone = float(self.tentry_a1.get())

bone = float(self.tentry_b1.get())

cone = float(self.tentry_c1.get())

done = float(self.tentry_d1.get())

atwo = float(self.tentry_a1.get())

btwo = float(self.tentry_b2.get())

ctwo = float(self.tentry_c2.get())

dtwo = float(self.tentry_d2.get())

athree = float(self.tentry_a3.get())

bthree = float(self.tentry_b3.get())

cthree = float(self.tentry_c3.get())

dthree = float(self.tentry_d3.get())

x = sy.Symbol('x')

y = sy.Symbol('y')

z = sy.Symbol('z')

f1 = aone*x + bone*y + cone*z + -1*done

f2 = atwo*x + btwo*y + ctwo*z + -1*dtwo

f3 = athree*x + bthree*y + cthree*z + -1*dthree

t_resultTwo = sy.solve([f1, f2, f3], [x, y, z])

if x in t_resultTwo and y in t_resultTwo and z in t_resultTwo:

self.tresultX.set(t_resultTwo[x])

self.tresultY.set(t_resultTwo[y])

self.tresultZ.set(t_resultTwo[z])

elif x in t_resultTwo or y in t_resultTwo or z in t_resultTwo:

self.tresultX.set('無唯一解')

self.tresultY.set('無唯一解')

self.tresultZ.set('無唯一解')

else:

self.tresultX.set('無解')

self.tresultY.set('無解')

self.tresultZ.set('無解')

解一元二次方程

a = float(self.entry_a.get())

b = float(self.entry_b.get())

c = float(self.entry_c.get())

x = sy.Symbol('x')

tResult = sy.solve(a*x**2 + b*x + -1*c, x)

if tResult:

if len(tResult) == 2:

self.resultX1.set(tResult[0])

self.resultX2.set(tResult[1])

if len(tResult) == 1:

self.resultX1.set(tResult[0])

self.resultX2.set(tResult[0])

else:

self.resultX1.set("無解")

self.resultX2.set("無解")

解三元一次方程

def fCount(self):

a = float(self.fentry_a.get())

b = float(self.fentry_b.get())

c = float(self.fentry_c.get())

d = float(self.fentry_d.get())

x = sy.Symbol('x')

f = a*x**3 + b*x**2 + c*x + 1*d

fResult = sy.solve(f, x)

if fResult:

if len(fResult) == 3:

self.fresultX1.set(fResult[0])

self.fresultX2.set(fResult[1])

self.fresultX3.set(fResult[2])

elif len(fResult) == 1:

self.fresultX1.set(fResult[0])

self.fresultX2.set(fResult[0])

self.fresultX3.set(fResult[0])

else:

self.fresultX1.set("無解")

self.fresultX2.set("無解")

self.fresultX3.set("無解")

四.界面以及結果展示

1.標準模式界面

2.二元一次方程界面

3.三元一次方程的界面

4.一元二次方程界面

5.一元三次方程的求解

總結

這份計算器使用了tkinter界面庫進行顯示,不過python的自帶界面庫和java一樣都太簡陋了,不過做個簡單的界面問題不大。

使用python的eval函數方便直接進行計算,python具有豐富的庫資源的確可以很大程度上幫助完成功能,不過也不能放棄自己的思考,所以這份計算器應該還能繼續改進。

此計算器存在一定的問題,如果結果的位數超過label可以顯示的范圍,就無法看到頭幾位的結果,這個暫時沒有想到如何解決。

總結

以上是生活随笔為你收集整理的python计算器函数图像_Python图形计算器,python,图像,化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。