1、打开idle。点击file,然后点击new file 这是创建一个新的文件。新建...
答:1、打开idle。点击file,然后点击new file.这是创建一个新的文件。 新建一个文件之后,我们输入第一行代码,使用print函数,在屏幕上打印一句话,其中字符串要使用双引号,输入法要使用英文输入法,如果符号使用中文输入法输入,就会出现错误。p...
2020-11-17 回答者: 环球青藤 1个回答
python sympy中生成的公式怎么粘到word里
答:右键选 show math as→mathML Code 全选复制,在word中右键以文本形式粘贴
2018-01-27 回答者: 夜歌在路上 2个回答
如何使用python提取并处理word文档中插入的mathtyp...
答:我没做过,只能提供大概思路给你。这是mathtype的SDK:,里面关于API的描述: MathType API Documentation The MathType API allows you to call functions used by the MathType Commands For Word. On Windows, this API is split between MathP...
2017-10-03 回答者: 天天不看java 1个回答
如何用python写这个代码
问:使用两个参数定义一个名为dictionaryToListOfValues的函数。 此函数的第...
答:使用Python自带的IDLE 在开始-->程序-->Python2.5(视你安装的版本而不同)中找到IDLE(Python GUI)。 点击后弹出如下窗体: 1,在>>>提示符后输入代码,回车,就可以执行此代码。 IDLE支持语法高亮,支持自动缩进,支持方法提示,不过提示的很慢。...
2019-10-17 回答者: 司马刀剑 2个回答 3
如何用python编写计算器
答:我想你的需求应该是一个图形界面的程序,而不是简单的在命令行上输入。 那么,要做的第一件事就是选择一个图形界面套件。可以使用原生的TK,也可以用跨平台性能很好的wxPython,或者是整体结构很像MFC的PyWin32。至于pyGTK,pyQT,都是可选的,但...
2011-05-30 回答者: 碧蓝右耳 3个回答 6
用Python编写代码1×2×3+4×5×6+7×8×9+++···99×100×1...
答:t=1 for i in range(1,102): t*=i print(t)
2020-04-05 回答者: 知道网友 1个回答 2
python 如何识别docx中的公式
答:import fnmatch, os, sys, win32com.client readpath=r'D:\123' wordapp = win32com.client.gencache.EnsureDispatch("Word.Application") try: for path, dirs, files in os.walk(readpath): for filename in files: if not fnmatch.fnmatch(fi...
2016-07-09 回答者: 知道网友 1个回答 2
如何用Python代码运行Word中的VBA
问:请问有什么好的办法用Python代码运行Word中的VBA吗, 具体需要import哪...
答:安装pypiwin32 import win32com.client app= win32com.client.Dispatch("word.Application") app.Workbooks.Open("宏代码所在文件路径") app.Application.Run("宏名称") app.Application.Quit()
2019-08-31 回答者: 娘化的新世界 1个回答
用Python写一个,两个数的加,减,乘,除的函数,...
答:我课程中的部分代码(除没写): def f_add(a,b): return a+bdef f_mul(a,b): return a*bdef f_sub(a,b): return a-b def g1(f,a,b): return f(a,b)a,b,c,d = 1,2,3,4print g1(f_sub, g1(f_mul, g1(f_add,a,b), c), d), g1(f_mul, g1(f_add,a,b)...
2017-11-21 回答者: 黑板客 1个回答 4
python编写2个函数代码,实现求最小公倍数和最大公...
问:使用两个函数实现,最小公倍数和最大公约数
答:def gcd(a, b): # 求最大公约数 x = a % b while (x != 0): a, b = b, x x = a % b return bdef lcm(a,b): # 求最小公倍数 return a*b//gcd(a,b) 程序缩进如图所示
这是个代码, 使用Tkinter图形库,如果你是用的linux系统 记得将第一行改为from tkinter import *
这个代码实现的挺简单,并不是很复杂的科学计算器界面,你可以以此为基础,添加自己想要的东西:给你个截图:
代码是如下, 我就不给你添注释了啊:
#!/usr/bin/env python3.4from Tkinter import *
import parser
root = Tk()
root.title('Calculator')
i = 0
def factorial():
"""Calculates the factorial of the number entered."""
whole_string = display.get()
number = int(whole_string)
fact = 1
counter = number
try:
while counter > 0:
fact = fact*counter
counter -= 1
clear_all()
display.insert(0, fact)
except Exception:
clear_all()
display.insert(0, "Error")
def clear_all():
"""clears all the content in the Entry widget"""
display.delete(0, END)
def get_variables(num):
"""Gets the user input for operands and puts it inside the entry widget"""
global i
display.insert(i, num)
i += 1
def get_operation(operator):
"""Gets the operand the user wants to apply on the functions"""
global i
length = len(operator)
display.insert(i, operator)
i += length
def undo():
"""removes the last entered operator/variable from entry widget"""
whole_string = display.get()
if len(whole_string): ## repeats until
## now just decrement the string by one index
new_string = whole_string[:-1]
print(new_string)
clear_all()
display.insert(0, new_string)
else:
clear_all()
display.insert(0, "Error, press AC")
def calculate():
"""
Evaluates the expression
ref : http://stackoverflow.com/questions/594266/equation-parsing-in-python
"""
whole_string = display.get()
try:
formulae = parser.expr(whole_string).compile()
result = eval(formulae)
clear_all()
display.insert(0, result)
except Exception:
clear_all()
display.insert(0, "Error!")
root.columnconfigure(0,pad=3)
root.columnconfigure(1,pad=3)
root.columnconfigure(2,pad=3)
root.columnconfigure(3,pad=3)
root.columnconfigure(4,pad=3)
root.rowconfigure(0,pad=3)
root.rowconfigure(1,pad=3)
root.rowconfigure(2,pad=3)
root.rowconfigure(3,pad=3)
display = Entry(root, font = ("Calibri", 13))
display.grid(row = 1, columnspan = 6 , sticky = W+E)
one = Button(root, text = "1", command = lambda : get_variables(1), font=("Calibri", 12))
one.grid(row = 2, column = 0)
two = Button(root, text = "2", command = lambda : get_variables(2), font=("Calibri", 12))
two.grid(row = 2, column = 1)
three = Button(root, text = "3", command = lambda : get_variables(3), font=("Calibri", 12))
three.grid(row = 2, column = 2)
four = Button(root, text = "4", command = lambda : get_variables(4), font=("Calibri", 12))
four.grid(row = 3 , column = 0)
five = Button(root, text = "5", command = lambda : get_variables(5), font=("Calibri", 12))
five.grid(row = 3, column = 1)
six = Button(root, text = "6", command = lambda : get_variables(6), font=("Calibri", 12))
six.grid(row = 3, column = 2)
seven = Button(root, text = "7", command = lambda : get_variables(7), font=("Calibri", 12))
seven.grid(row = 4, column = 0)
eight = Button(root, text = "8", command = lambda : get_variables(8), font=("Calibri", 12))
eight.grid(row = 4, column = 1)
nine = Button(root , text = "9", command = lambda : get_variables(9), font=("Calibri", 12))
nine.grid(row = 4, column = 2)
cls = Button(root, text = "AC", command = clear_all, font=("Calibri", 12), foreground = "red")
cls.grid(row = 5, column = 0)
zero = Button(root, text = "0", command = lambda : get_variables(0), font=("Calibri", 12))
zero.grid(row = 5, column = 1)
result = Button(root, text = "=", command = calculate, font=("Calibri", 12), foreground = "red")
result.grid(row = 5, column = 2)
plus = Button(root, text = "+", command = lambda : get_operation("+"), font=("Calibri", 12))
plus.grid(row = 2, column = 3)
minus = Button(root, text = "-", command = lambda : get_operation("-"), font=("Calibri", 12))
minus.grid(row = 3, column = 3)
multiply = Button(root,text = "*", command = lambda : get_operation("*"), font=("Calibri", 12))
multiply.grid(row = 4, column = 3)
divide = Button(root, text = "/", command = lambda : get_operation("/"), font=("Calibri", 12))
divide.grid(row = 5, column = 3)
# adding new operations
pi = Button(root, text = "pi", command = lambda: get_operation("*3.14"), font =("Calibri", 12))
pi.grid(row = 2, column = 4)
modulo = Button(root, text = "%", command = lambda : get_operation("%"), font=("Calibri", 12))
modulo.grid(row = 3, column = 4)
left_bracket = Button(root, text = "(", command = lambda: get_operation("("), font =("Calibri", 12))
left_bracket.grid(row = 4, column = 4)
exp = Button(root, text = "exp", command = lambda: get_operation("**"), font = ("Calibri", 10))
exp.grid(row = 5, column = 4)
## To be added :
# sin, cos, log, ln
undo_button = Button(root, text = "<-", command = undo, font =("Calibri", 12), foreground = "red")
undo_button.grid(row = 2, column = 5)
fact = Button(root, text = "x!", command = factorial, font=("Calibri", 12))
fact.grid(row = 3, column = 5)
right_bracket = Button(root, text = ")", command = lambda: get_operation(")"), font =("Calibri", 12))
right_bracket.grid(row = 4, column = 5)
square = Button(root, text = "^2", command = lambda: get_operation("**2"), font = ("Calibri", 10))
square.grid(row = 5, column = 5)
root.mainloop()