Math Problem Solver+ 2.0
Math Problem Solver+ 2.0这是之前写的一个数学计算的小工具,1.0的代码就不展示了,看看更新内容:
1.加入了检测垃圾邮件的发送
2.主界面加入随机数生成工具,使界面不再空荡荡
3.还加入了函数的计算
4.修复了一些已知bug
下面这个非常重要!!!下面这个非常重要!!!
1.记得先安装easygui模块!
2.把几何画板安装在该文件的目录下,否则会影响几何画板的使用(除非你不用)
上代码:
from math import *
from random import *
import sys
from easygui import enterbox,choicebox
import os
from tkinter import *
import tkinter.messagebox as g
from decimal import Decimal
global ver
ver=2.0
def sx_main():
def feedback():
g.showwarning(("Math Problem Solver+ "+str(ver)),"""Math Problem Solver+ 2.0对于邮件的发送会进行较为严格的审查。
对于明显的垃圾邮件会直接禁止发送,其他被拦截的邮件可自行选择""")
import smtplib
import re
from os import environ
from os.path import exists
from platform import system, node
from time import strftime
from email.mime.text import MIMEText
from email.utils import formataddr
from random import randint
from easygui import enterbox
title = ('Math Problem Solver+',ver)
my_sender = 'advance_software@126.com'
my_pass = 'QFAQPLFQZRZBMVWQ'
dt = strftime('%Y-%m-%d %H:%M:%S')
my_user = "taoyuanhang66@outlook.com"
username = environ['USERNAME']
system = system()
computer = node()
number = enterbox("请输入反馈内容:")
name_nc=enterbox("请输入名字(昵称):")
if number == None or name_nc == None:
g.showinfo("","已取消发送!")
return None
elif number =='':
g.showinfo("","系统检测到发送垃圾邮件行为,已自动取消发送!")
return None
elif number.count(number)==len(number) or name_nc.count(name_nc)==len(name_nc):
if g.askyesno("","系统根据相同字符串检测到发送垃圾邮件行为,已自动取消发送!\n如果继续发送,将有可能会被识别为垃圾邮件,继续吗")==True:
number="(根据相同字符串识别为垃圾邮件)\n"+number
else:
return None
elif number.isdecimal()==True:
if g.askyesno("","系统根据字符串为数字检测到发送垃圾邮件行为,已自动取消发送!\n如果继续发送,将有可能会被识别为垃圾邮件,继续吗")==True:
number="(根据字符串为数字识别为垃圾邮件)\n"+number
else:
return None
elif number.count(".")+number.count(",")+number.count(",")+number.count("。")+number.count("?")+number.count("?")+number.count(" ")==0 and len(number)>=10:
if g.askyesno("","系统根据超过限定字数且没有断句检测到发送垃圾邮件行为,已自动取消发送!\n如果继续发送,将有可能会被识别为垃圾邮件,继续吗")==True:
number="(根据超过限定字数且没有断句识别为垃圾邮件)\n"+number
else:
return None
elif len(number)<=4:
if g.askyesno("","系统根据字数过少检测到发送垃圾邮件行为,已自动取消发送!\n如果继续发送,将有可能会被识别为垃圾邮件,继续吗")==True:
number="(根据字数过少识别为垃圾邮件)\n"+number
else:
return None
else:
tsfh=[",",",",".","。","[","【","】","+",
"-","*","/","(",")","(",")","!",
"!","?","?","#","@","¥","$","%",
"^","&","<",">","~","_","…"]
c=0
for i in tsfh:
c+=number.count(i)
if c>len(number)/4:
if g.askyesno("","系统根据特殊符号过多检测到发送垃圾邮件行为,已自动取消发送!\n如果继续发送,将有可能会被识别为垃圾邮件,继续吗")==True:
number="(根据特殊符号过多识别为垃圾邮件)\n"+number
else:
return None
else:
if g.askyesno("",("系统未检测到发送垃圾邮件行为!\n继续发送吗?\n预览:\n"+name_nc+"\n"+number))==True:
pass
else:
return None
err = Exception
def mail():
global err
ret = True
try:
msg = MIMEText(number, 'plain', 'utf-8')
msg['From'] = formataddr()
msg['To'] = formataddr(["", my_user])
msg['Subject'] = "用户使用反馈"
server = smtplib.SMTP_SSL("smtp.126.com", 465)
server.login(my_sender, my_pass)
server.sendmail(my_sender, , msg.as_string())
server.quit()
except Exception as e:
ret = False
err = str(e)
return ret
def checkmail(email):
reg = "\w+[@]+(\.+)+"
result = re.findall(reg, email)
if result:
ret = mail()
if ret:
g.showinfo("反馈", '发送成功!')
else:
g.showerror("反馈", '邮件发送失败!')
else:
g.showerror('Math Problem Solver+', '您的输入不合法,请重新输入!')
if __name__ == '__main__':
checkmail(my_user)
def aboutm():
g.showinfo("About Math Problem Solver+","""Math Problem Solver+ 1.0
Copyright© 2023 陶远航
All Rights Reserved.
警告:
不能过于依赖此工具
程序及源代码仅供学习交流,
未经作者允许不可用于商业用途!""")
def guifan():
g.showwarning("","""由于我的能力有限,无法做出以下的功能,以后可能会修复:
1、数字不能直接写在字母、括号前,比如,把“5x”替换成“5*x”
2、注意,把所有的次方改成“**”,比如,“5³”要替换成“5**3”
3、乘号“×”替换成“*”
上述问题在以后版本会改进,谢谢!
""")
def jhhb():
if g.askyesno("警告","开启几何画板会导致Math Problem Solver+未响应,继续吗?"):
jhhbpath=os.path.join(os.path.dirname(__file__), 'GSP5chs.exe')
os.system(str('"'+jhhbpath+'"'))
return None
def menuCommand() :
g.showinfo("功能未开放","功能未开放,您可以使用其他功能")
def _quit():
win.quit()
win.destroy()
sys.exit()
def njh(bianshu=None):
try:
if bianshu==None:
bianshu=int(enterbox("请输入边数:",""))
else:
bianshu=int(bianshu)
except:
g.showerror("","请输入正确的值!")
return None
if bianshu<=2:
g.showerror("","请输入正确的值!")
return None
else:
g.showinfo("",("内角和为",str((bianshu-2)*180),"°"))
def waijiao(bianshu=None):
try:
if bianshu==None:
bianshu=int(enterbox("请输入边数:",""))
else:
bianshu=int(bianshu)
except:
g.showerror("","请输入正确的值!")
return None
if bianshu<=2:
g.showerror("","请输入正确的值!")
return None
else:
g.showinfo('',("正",bianshu,"边形的外角为",str(360-(bianshu-2)*180/bianshu)))
def zhouchang(n=None):
if n==None:
try:
n=int(enterbox("请输入边数"))
except:
g.showerror("","请输入正确的值!")
return None
if n<=2:
g.showerror("","边数不能小于二!")
return None
b_list=[]
for i in range(n):
try:
b_list.append(int(enterbox(("请输入第",i+1,"边边长"))))
except:
g.showerror("","请输入正确的值!")
return None
g.showinfo("",str(sum(b_list)))
return None
def sjx_mj_dg():
try:
gao=int(enterbox("请输入高:"))
di=int(enterbox("请输入底:"))
g.showinfo("",("面积为",str(gao*di/2)))
return None
except:
g.showerror("","请输入正确的值!")
return None
def sjx_mj_sb():
try:
s1=int(enterbox("请输入第一边长:"))
s2=int(enterbox("请输入第二边长:"))
s3=int(enterbox("请输入第三边长:"))
p=(s1+s2+s3)/2
s=sqrt(p*(p-s1)*(p-s2)*(p-s3))
g.showinfo("",("p=(",s1,"+",s2,"+",s3,")÷2 =",(s1+s2+s3)/2,
"面积为√",str(p*(p-s1)*(p-s2)*(p-s3)),"即",str(s)))
return None
except:
g.showerror("","请输入正确的值!")
return None
def zjsjx_mj_dg():
try:
a=int(enterbox("直角边长:"))
b=int(enterbox("另一个直角边长:"))
g.showinfo("",str(a*b/2))
return None
except:
g.showerror("","请输入正确的值!")
return None
def zjsjx_xb():
try:
a=int(enterbox("直角边长:"))
b=int(enterbox("另一个直角边长:"))
g.showinfo("",("√",str(pow(a,2)+pow(b,2)),",即",str(sqrt(pow(a,2)+pow(b,2)))))
return None
except:
g.showerror("","请输入正确的值!")
return None
def dysjx_yd_zc():
try:
yao=int(enterbox("腰长:"))
di=int(enterbox("底长:"))
g.showinfo("",("周长为",str(2*yao+di)))
return None
except:
g.showerror("","请输入正确的值!")
return None
def sbx_mj_ty(state=None):
if state=="1":
try:
a=int(enterbox("边长:"))
g.showinfo("",str(a**2))
return None
except:
g.showerror("","请输入正确的值!")
return None
elif state=="2":
try:
a=int(enterbox("长:"))
b=int(enterbox("宽:"))
g.showinfo("",str(a*b))
return None
except:
g.showerror("","请输入正确的值!")
return None
elif state=="3":
try:
a=int(enterbox("底:"))
b=int(enterbox("高:"))
g.showinfo("",str(a*b))
return None
except:
g.showerror("","请输入正确的值!")
return None
elif state=="4":
try:
a=int(enterbox("上底:"))
c=int(enterbox("下底:"))
b=int(enterbox("高:"))
g.showinfo("",str((a+c)*b/2))
return None
except:
g.showerror("","请输入正确的值!")
return None
elif state==None:
return None
def sbx_bc_ty(state=None):
try:
if state=="None":
return None
elif state=="1":
s=int(enterbox("面积:"))
g.showinfo("",str(sqrt(s)))
return None
elif state=="2":
s=int(enterbox("面积:"))
a=int(enterbox("长(或宽):"))
g.showinfo("",str(s/a))
return None
elif state=="3":
s=int(enterbox("面积:"))
a=int(enterbox("底(或高):"))
g.showinfo("",str(s/a))
return None
else:
return None
except:
g.showerror("","请输入正确的值!")
def sbx_zc_ty(state=None):
if state==1:
try:
g.showinfo("",str(4*int(enterbox("请输入边长:"))))
except:
g.showerror("","请输入正确的值!")
elif state==2:
try:
g.showinfo("",str(2*int(enterbox("请输入长:"))+2*int(enterbox("请输入宽:"))))
except:
g.showerror("","请输入正确的值!")
elif state==3:
try:
g.showinfo("",str(2*int(enterbox("请输入其中一组对边的长:"))+2*int(enterbox("请输入另一组对边的长:"))))
except:
g.showerror("","请输入正确的值!")
elif state==4:
try:
g.showinfo("",str(int(enterbox("请输入上底:"))+int(enterbox("请输入下底:"))+int(enterbox("请输入腰:"))+int(enterbox("请输入另一条腰:"))))
except:
g.showerror("","请输入正确的值!")
elif state==5:
try:
g.showinfo("",str(int(enterbox("请输入第一条边长:"))+int(enterbox("请输入第二条边长:"))+int(enterbox("请输入第三条边长:"))+int(enterbox("请输入第四条边长:"))))
except:
g.showerror("","请输入正确的值!")
def sbx_mj_ts():
try:
s1=int(enterbox("请输入第一边长:"))
s2=int(enterbox("请输入第二边长:"))
s3=int(enterbox("请输入第三边长:"))
s4=int(enterbox("请输入第四边长:"))
s5=int(enterbox("请输入第对角线长(第二边长和第三边长的夹角的角平分线在四边形内的长度):"))
p=(s1+s2+s5)/2
p2=(s3+s4+s5)/2
s=sqrt(p*(p-s1)*(p-s2)*(p-s5))+sqrt(p*(p2-s3)*(p2-s4)*(p2-s5))
g.showinfo("",(str(s)))
return None
except:
g.showerror("","请输入正确的值!")
return None
win = Tk()
win.title("Math Problem Solver+ 1.0")
win.geometry('350x150+300+200')
mainmenu = Menu (win)
jihemenu = Menu (mainmenu, tearoff=False)
tongyong=Menu(jihemenu,tearoff=0)
#######################通用###############################
tongyong.add_command(label='内角和',command=njh)
tongyong.add_command(label='外角',command=waijiao)
jihemenu.add_cascade(label="通用",menu=tongyong)
#######################通用###############################
#######################三角形##########################################
sjx=Menu(jihemenu,tearoff=0)
sjx.add_command(label='周长',command=lambda:zhouchang(3))
#######################三角形面积##########################
sjxmianji=Menu(jihemenu,tearoff=0)
sjxmianji.add_command(label='已知底和高',command=lambda:sjx_mj_dg())
sjxmianji.add_command(label='已知三边长',command=lambda:sjx_mj_sb())
zjsjx=Menu(jihemenu,tearoff=0)
zjsjx.add_command(label='求面积',command=zjsjx_mj_dg)
zjsjx.add_command(label='求斜边长',command=zjsjx_xb)
sjxmianji.add_cascade(label='直角三角形(特殊)',menu=zjsjx)
sjx.add_cascade(label='面积',menu=sjxmianji)
#######################三角形面积##########################
#######################直角三角形##########################
#menu在上面
sjx.add_cascade(label='直角三角形',menu=zjsjx)
#######################直角三角形##########################
#######################等腰三角形##########################
dysjx=Menu(jihemenu,tearoff=0)
dysjx.add_command(label='已知腰底求周长',command=dysjx_yd_zc)
sjx.add_cascade(label='等腰三角形',menu=dysjx)
#######################等腰三角形##########################
jihemenu.add_cascade(label="三角形",menu=sjx)
#######################三角形###########################################
#######################四边形###########################################
sbx=Menu(jihemenu,tearoff=0)
#######################正方形###########################################
zfx=Menu(jihemenu,tearoff=0)
zfx.add_command(label='求面积',command=lambda:sbx_mj_ty(state="1"))
zfx.add_command(label='求边长',command=lambda:sbx_bc_ty(state="1"))
zfx.add_command(label='求周长',command=lambda:sbx_zc_ty(state=1))
sbx.add_cascade(label='正方形',menu=zfx)
#######################正方形###########################################
#######################长方形###########################################
cfx=Menu(jihemenu,tearoff=0)
cfx.add_command(label='求面积',command=lambda:sbx_mj_ty(state="2"))
cfx.add_command(label='求长/宽',command=lambda:sbx_bc_ty(state="2"))
cfx.add_command(label='求周长',command=lambda:sbx_zc_ty(state=2))
sbx.add_cascade(label='长方形',menu=cfx)
#######################长方形###########################################
#######################平行四边形########################################
pxsbx=Menu(jihemenu,tearoff=0)
pxsbx.add_command(label='求面积',command=lambda:sbx_mj_ty(state="3"))
pxsbx.add_command(label='求底/高',command=lambda:sbx_bc_ty(state="3"))
pxsbx.add_command(label='求周长',command=lambda:sbx_zc_ty(state=3))
sbx.add_cascade(label='平行四边形',menu=pxsbx)
#######################平行四边形########################################
#######################梯形#############################################
tx=Menu(jihemenu,tearoff=0)
tx.add_command(label='求面积',command=lambda:sbx_mj_ty(state="4"))
tx.add_command(label='求上底/下底/高',command=menuCommand)
tx.add_command(label='求周长',command=lambda:sbx_zc_ty(state=4))
sbx.add_cascade(label='梯形',menu=tx)
#######################梯形#############################################
#######################任意四边形########################################
rysbx=Menu(jihemenu,tearoff=0)
rysbx.add_command(label='求面积',command=sbx_mj_ts)
rysbx.add_command(label='求周长',command=lambda:sbx_zc_ty(state=4))
sbx.add_cascade(label='任意四边形',menu=rysbx)
#######################任意四边形########################################
jihemenu.add_cascade(label="四边形",menu=sbx)
#######################四边形###########################################
wbx=Menu(jihemenu,tearoff=0)
wbx.add_cascade(label='内角和',command=njh)
jihemenu.add_cascade(label="五边形及以上",menu=wbx)
jihemenu.add_separator()
jihemenu.add_command(label="打开几何画板",command=jhhb)
mainmenu.add_cascade(label="几何",menu=jihemenu)
def calc():
guifan()
try:
g.showinfo("",eval(enterbox("式子:")))
return None
except:
g.showerror("","运行错误!")
def kaifang():
guifan()
a = int(enterbox("请输入你要开方的数:"))
b = int(enterbox("请输入你要开几次方"))
x = 1
b1 = b - 1
while True:
try:
y = (b1 * x + a / (x ** b1)) / b
except OverflowError:
g.showerror("数字可能太大了!")
if y == x:
break
x = y
g.showinfo("",x)
def gaojimoshi():
guifan()
mingling=enterbox("式子或任意命令:")
try:
g.showinfo("",(str(mingling),"执行成功!返回值:",eval(mingling)))
return None
except:
try:
g.showinfo("",(str(mingling),"执行成功!返回值:",exec(mingling)))
return None
except:
g.showerror("","运行错误!请检查输入是否正确!")
return None
def ysfj():
try:
fi=int(enterbox("请输入一个正整数"))
except:
g.showerror("","请输入正确的值!")
xd = list()
if fi <= 3:
xd.append(fi)
if fi >= 4:
x = 2
while fi >= x ** 2:
if fi % x != 0:
x += 1
if fi % x == 0:
xd.append(str(x))
fi = int(fi / x)
xd.append(str(fi))
if len(xd) == 1 and fi != 1:
ff = "质数不能分解"
g.showerror("",ff)
if fi == 1:
g.showerror("","1不能分解")
if len(xd) > 1:
ff = "*".join(xd)
g.showinfo("",ff)
def isprime():
try:
n=int(enterbox("请输入一个正整数:"))
except:
g.showerror("","请输入正确的值!")
return None
if n>2:
for i in range(n):
if n%(i+2)==0:
g.showinfo("",(n,"不是质数,",(i+2),"*",int(n/(i+2)),"=",n))
return None
else:
continue
g.showinfo("",(n,"是质数"))
def hanshu():
while True:
hanshu_list = ['cos(a)',
'sin(a)',
'tan(a)',
'更多运算请见Math Problem Solver+ 更高版本',
'退出']
choice=choicebox(msg='选择小工具',title='选择小工具',choices=hanshu_list)
if choice=="退出":
break
elif choice=="cos(a)":
try:
g.showinfo("",cos(int(enterbox("cos(a)中a的值"))))
except:
g.showerror("","请输入正确的值!")
elif choice=="sin(a)":
try:
g.showinfo("",sin(int(enterbox("sin(a)中a的值"))))
except:
g.showerror("","请输入正确的值!")
elif choice=="tan(a)":
try:
g.showinfo("",tan(int(enterbox("tan(a)中a的值"))))
except:
g.showerror("","请输入正确的值!")
else:
break
var_Name=StringVar()
var_Name.set('0')
var_Pwd=StringVar()
var_Pwd.set('100')
var_Num=StringVar()
var_Num.set('5')
var_Num_2=StringVar()
var_Num_2.set('2')
def login():
try:
_min=int(var_Name.get())
_max=int(var_Pwd.get())
random_number_list=[]
for i in range(int(var_Num.get())):
random_number_list.append(randint(_min,_max))
g.showinfo("",random_number_list)
except:
g.showerror("Error","请输入正确的值!")
def login_2():
try:
_min=float(var_Name.get())
_max=float(var_Pwd.get())
random_number_list=[]
for i in range(int(var_Num.get())):
rand=uniform(_min,_max)
if random_number_list==[]:
random_number_list.append(str(format(rand,('.'+var_Num_2.get()+"f"))))
else:
random_number_list.append(","+str(format(rand,('.'+var_Num_2.get()+"f"))))
g.showinfo("",random_number_list)
except:
g.showerror("Error","请输入正确的值!")
sjstxt=Label(win,text='随机数生成',width=80)
labname=Label(win,text='最小值:',width=80)
labpwd=Label(win,text='最大值:',width=80)
labnum=Label(win,text='个数:',width=80)
labnum_2=Label(win,text='小数位数(仅限小数):',width=180)
entname=Entry(win,width=100,textvariable=var_Name)
entpwd=Entry(win,width=100,textvariable=var_Pwd)
entnum=Entry(win,width=100,textvariable=var_Num)
entnum_2=Entry(win,width=100,textvariable=var_Num_2)
but_Ok=Button(win,text='生成整数',command=login)
but_Ok_2=Button(win,text='生成小数',command=login_2)
sjstxt.place(x=20,y=5,width=80,height=20)
labname.place(x=20,y=30,width=80,height=20)
labpwd.place(x=20,y=60,width=80,height=20)
labnum.place(x=20,y=90,width=80,height=20)
labnum_2.place(x=20,y=120,width=120,height=20)
entname.place(x=120,y=30,width=80,height=20)
entpwd.place(x=120,y=60,width=80,height=20)
entnum.place(x=120,y=90,width=80,height=20)
entnum_2.place(x=150,y=120,width=80,height=20)
but_Ok.place(x=200,y=90,width=60,height=20)
but_Ok_2.place(x=200,y=120,width=60,height=20)
daishumenu = Menu (mainmenu, tearoff=False)
daishumenu.add_command(label="简易计算器",command=calc)
daishumenu.add_command(label="开方",command=kaifang)
daishumenu.add_command(label="多项式展开",command=menuCommand)
daishumenu.add_command(label="因数/式分解",command=ysfj)
daishumenu.add_command(label="随机数生成",command=menuCommand)
daishumenu.add_command(label="质数检测",command=isprime)
daishumenu.add_command(label="函数及其他复杂计算",command=hanshu)
daishumenu.add_separator()
daishumenu.add_command(label="高级模式",command=gaojimoshi)
mainmenu.add_cascade(label="代数",menu=daishumenu)
mainmenu.add_command(label="退出",command=_quit)
mainmenu.add_command(label="关于",command=aboutm)
mainmenu.add_command(label="反馈",command=feedback)
win.config(menu=mainmenu)
win.mainloop()
sx_main() 感谢分享,能配个软件截图就更好了
页:
[1]