Lv.1
无
在 【Python作品分享】Python 一句话计算器!喵论坛上所有自制计算器!【作品秀】 中回复
import easygui import turtle import math p=turtle.Pen() pen=turtle.Pen() s=turtle.Screen() s.setup(1000,700) p.penup() pen.penup() turtle.screensize(10000,10000)#准备 def chaifen(suanshi): # 拆分程序 count = 0 canshu = suanshi number = [] fuhao = [] # 对五种符号进行不同的处理 for i inrange(len(canshu)): if(canshu[i] == '+'): canshu = canshu.split('+', 1) fuhao.append('+') number.append(canshu[count]) count += 1 # print(fuhao) break if(canshu[i] == '-'): canshu = canshu.split('-', 1) fuhao.append('-') number.append(canshu[count]) count += 1 # print(fuhao) break if(canshu[i] == '*'): canshu = canshu.split('*', 1) fuhao.append('*') number.append(canshu[count]) count += 1 # print(fuhao) break if(canshu[i] == '/'): canshu = canshu.split('/', 1) fuhao.append('/') number.append(canshu[count]) count += 1 # print(fuhao) break if(canshu[i] == '^'): canshu = canshu.split('^', 1) fuhao.append('^') number.append(canshu[count]) count += 1 # print(fuhao) break if((('+'in canshu[-1])or('-'in canshu[-1])or('*'in canshu[-1])or('/'in canshu[-1])or('^'in canshu[-1]))and(('0'in canshu[-1])or('1'in canshu[-1])or('2'in canshu[-1])or('3'in canshu[-1])or('4'in canshu[-1])or('5'in canshu[-1])or('6'in canshu[-1])or('7'in canshu[-1])or('8'in canshu[-1])or('9'in canshu[-1]))): n1, f1 = chaifen(canshu[-1])#一次拆分还不够 return number + n1, fuhao + f1#递归拆分 else:#↑必须把之前的数据也加上! number.append(canshu[-1]) return number, fuhao # 返回结果 # def fan(l): # a = '' # i1 = (len(l) - 1) # for __count in range(len(l)): # a = (a + l[i1]) # i1 -= 1 # return a def calculator(chaifen_ed_suanshi): # 运算部分 num,f=chaifen_ed_suanshi f=''.join(f) # f=fan(f) #print(num) for i inrange(len(num)): if('!'in num [i]):#阶乘运算 num[i] = str(math.factorial(int(num[i].split ('!')[0]))) #print(num) if('√'in num [i]):#平方根运算 num[i] = str(math.sqrt(float(num[i].split('√')[-1]))) #print(num) if num[i]=='圆周率'or num[i]=='pi':#转化 num[i]=str(math.pi) if num[i]=='e'or num[i]=='E':#转化 num[i]=str(math.e) if('sin'in num[i]and(not'a'in num[i])):#三角函数运算 if'°'in num[i]:#角度 num[i] = num[i].split('sin')[-1] # easygui.msgbox(str(num[i])) num[i] = num[i].split('°')[0] # easygui.msgbox(str(num[i])) num[i] = float(num[i]) num[i] = str(math.sin(math.radians(num[i]))) else:#弧度 num[i] = num[i].split('sin')[-1] num[i]=float(num[i]) num[i] = str(math.sin(num[i])) #break if('cos'in num[i]and(not'a'in num[i])): if'°'in num[i]: num[i] = num[i].split('cos')[-1] # easygui.msgbox(str(num[i])) num[i] = num[i].split('°')[0] # easygui.msgbox(str(num[i])) num[i] = float(num[i]) num[i] = str(math.cos(math.radians(num[i]))) else: num[i] = num[i].split('cos')[-1] num[i] = float(num[i]) num[i] = str(math.cos(num[i])) #break if('tan'in num[i]and(not('a'in num[i]))): easygui.msgbox(num[i]) if'°'in num[i]: easygui.msgbox('du') num[i] = num[i].split('tan')[-1] easygui.msgbox(str(num[i])) num[i] = num[i].split('°')[0] easygui.msgbox(str(num[i])) num[i] = float(num[i]) num[i] = str(math.tan(math.radians(num[i]))) else: easygui.msgbox('h') num[i] = num[i].split('tan')[-1] easygui.msgbox(str(num[i])) num[i] = float(num[i]) num[i] = str(math.tan(num[i])) #break if'asin'in num[i]:#反三角函数运算 num[i] = num[i].split('asin')[-1] num[i] = float(num[i]) num[i] = str(math.asin(num[i])) #break if'acos'in num[i]: num[i] = num[i].split('acos')[-1] num[i] = float(num[i]) num[i] = str(math.acos(num[i])) #break if'atan'in num[i]: num[i] = num[i].split('atan')[-1] num[i] = float(num[i]) num[i] = str(math.atan(num[i])) #break for i inrange(len(num)): num[i] = float(num[i])#转化成数字 result = num[0] #print(num,result) for i inrange(len(f)): if f[i]=='+': result+=num[i+1] if f[i] == '-': result -= num[i+1] if f[i]=='*': result*=num[i+1] if f[i] == '/': result /= num[i+1] if f[i] == '^': result **= num[i+1] #对五种符号分类运算↑ if'.' == list(str(result))[-2]and'0' == list(str(result))[-1]:#把类似1.0,15.0的结果的末尾去掉,再返回结果 returnstr(result).split('.0')[0] else: return result#正常返回结果
pen.goto(-250, 300) pen.write('欢迎使用“超级喵”计算器,使用提示如下:↓', font=('Arial', 20, 'normal')) pen.goto(-450, 260) pen.write('输入“数字加符号加数字”以此类推进行运算(符号为+,-,*,/,^,!,√等)', font=('Arial', 20, 'normal')) pen.goto(-130, 220) pen.write('第一个数不能是负数', font=('Arial', 20, 'normal')) pen.goto(-145, 180) pen.write('鼠标模式:戳“exit”退出', font=('Arial', 20, 'normal')) # 提示 pen.goto(-125,140) pen.write('键盘模式:按cansel', font=('Arial', 20, 'normal')) pen.hideturtle() def main():#打包主函数 a = '' b = '' p.goto(-450,0) p.clear() whileTrue: try: if easygui.ynbox('要用鼠标输入还是键盘输入(默认键盘)','超级喵计算器',('鼠标','键盘')):#输入模式选择 while b!= '=': b=easygui.choicebox('输入算式','超级喵计算器',('e','pi','sin','cos','tan','asin','acos','atan','exit','.','°','0','1','2','3','4','5','6','7','8','9','+','-','*','/','^','!','√','=','<-|x|','all_clear')) if'exit'in b:# 退出 quit() #return 'exit' if b != '<-|x|'and b != 'all_clear':# ↑输入内容 a += b # ←保存输入 p.write(b, font=('Arial', 90, 'normal')) if b=='sin'or b=='cos'or b=='tan': p.forward(180) elif b=='asin'or b=='acos'or b=='atan':#对不同长度的输入做不同的处理 p.forward(250) else: p.forward(100) elif b == 'all_clear': a = ''#清空 b = '' p.goto(-450, 0) p.clear() continue #输入算式 else: p.undo() p.undo()#回删一个 a=''.join(list(a)[0:len(a)-1]) if p.xcor() >= 450: p.goto(-450,p.ycor()-100) # easygui.msgbox(a) a = a.split('=')[0] else: a = turtle.textinput('超级喵计算器','输入算式') if a isNone: quit() #return 'exit' p.write(calculator(chaifen(a)), font=('Arial', 100, 'normal')) easygui.msgbox('喵进行下一次计算','超级喵计算器','快喵') p.clear()#重置 p.goto(-450, 0) a = '' b = '' except ValueError: easygui.msgbox('看提示!不要乱加减符号和数字!不要输入字母等无关内容!','超级喵计算器')#输入有误 main() #输入错误后重新递归一次,进行下一次计算 except ZeroDivisionError: easygui.msgbox('不能除以0','超级喵计算器') main() except IndexError: easygui.msgbox('不能空打', '超级喵计算器') main()
except TypeError: easygui.msgbox('谁tm让你点×的?!', '超级喵计算器') main() except OverflowError: easygui.msgbox('太大了!!!', '超级喵计算器') main()
main() # 调用
2020-04-11T20:06:39 点赞:1
在 【Python作品分享】microbit-自动提醒装置【教程贴】 中回复
水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水
2020-04-12T11:53:46 点赞:0
在 【Python作品分享】一个极其普通的计算器1.9【作品秀】 中回复
大家在评论区说出自己的想法吧,到底用eval,还是我的算法?
PS:新来的同学可以看之前的计算器版本(v1.1以上)都有详细的、带注释的计算器算法
2020-04-16T17:06:40 点赞:0
在 【Python作品分享】一个极其普通的计算器1.9【作品秀】 中回复
对于程序的优化,以后肯定会做的。
我现在是在问下一个版本的更新去向!
是否替换计算核心?
2020-04-17T09:31:53 点赞:0
在 【Python作品分享】一个极其普通的计算器1.9【作品秀】 中回复
各位注意一下,周日晚24点是发表看法的最后期限!过了这个时间点就没用了!作者就会按自己的思路更新了!
2020-04-18T19:05:16 点赞:0
在 【Python作品分享】克仸投入婆热的身上【求助帖】 中回复
重大科技和福克斯的结婚证安慰他就和我卡尔特让他让他过户uuu亚尔eat人员通过多方发个言颓然哇76二u调试人员待遇的结构化的法国人他虽然他由于房价和风控合规意图体育瑟日特呃676889有热7髚儿童语言容忍他的图图有任何的私人恩怨态度和方式大哥瑟日特润色天文二胎仍如第一天的人哇有人图一图一是他同意瑟日特犹太人犹太人威尔特瑞特位移云图教育体育通过多方而是热体个月图五同人图第一天德国法国和我热瓦条约玩56英特热死人放鸽子晓得他也热特热天热阿凡达格瑞特额我让他
2020-04-18T19:08:46 点赞:0
在 【Python作品分享】克仸投入婆热的身上【求助帖】 中回复
巛巜巟巠巣巤匘巪巬巭巯巰巵巶巸巹巺巼巿帀帄帇帉帊帋帍帎帑帒帓帗帙帞帟帠帡帢帣帤帥帨帩帪帬帯帰帱帲帴帵帶帷帹帺帾帿幀幁幃幆幇幈幉幊幋幌幍幎幏幐幑幒幓幖幗幘幙幚幛幜幝幞幟幠幢幤幥幦幧幨幩幪幫幬幭幮幯幰幱幵幷幹幾庀庁庂広庅庈庉庋庌庍庎庑庖庘庛庝庠庡庢庣庤庥庨庩庪庫庬庮庯庰庱庲庳庴庹庺庻庼庽庿廀廁廃廄廅廆廇廈廋廌廍廎廏廐廑廒廓廔廕廗廘廙廚廛廜廝廞廟廠廡廢廤廥廦廧廨廩廪廫廬廭廮廯廰廱廲廳
2020-04-18T19:09:48 点赞:0
在 【Python作品分享】新的作品 中回复
arte安康突然还款流水人家挺好奥克兰展开了hark灵活性走i啊惹她后来看人家推动法国空军洞里萨日啊看人家而又富有哈哈特哦iui接口设计骨灰离开教室热火有俩入院后惯性矩与黑色人口埃里克换人了客户购房的公开十一而离开皇宫饭店冷库加油哈俄日u哦阿尔哦i他一直刻录机和各方面咱还有块元素拉库塞然后就哭了hi头上有还款记录和通用库沟通5嚄色iu要退货退款记录和斯科拉液体u人离开,第三个害死了如图以及欧斯语和国际化的疯狂经验和实力同居一韩国科学家和那个路口让大家会议室老师看人家好意思哦额u一天几个客户来访盎司附近客观上哈哈恩科举时代光华付款就kJSErfe色卡让他噶快角色高科技啊热五月份看这个hare空格和喵的健康两个艾利卡u加热艰苦奋斗总不能让火箭股份的借款人ui哦天涯欧斯大人和发动机可变你怎么消防规范
2020-04-20T10:56:55 点赞:0
在 【计算器消息】 中回复
1.0-1.7(easygui+trutle)版本使用的是我的算法,1.8-1.11(easygui+tkinter)使用的是eval算法。“tkinter+我的算法”版本会从2.0开始命名。记住哦!
2020-04-26T14:12:40 点赞:0