用户:查看:10 回复:7 评论:10 创建时间:2020-05-15T09:15:37
print("欢迎进入计算器。不能输入小数。")
sleep(1)
a = input("加法按1,乘法按2,减法按3,除法按4,平方按5,立方按6,多次方按7,平方根按8,平方差(两个数)按9,阶乘按10,立方差按11,取余按12,最大公约数按13,最小公倍数按14,平均数、方差、中位数按15,立方根按16,判断质数合数按17,绝对值按18,exp按19,cos按20,反cos按21,sin按22,反sin按23,tan按24,反tan按25,判断整除按26,π按27,e按28,约分按29,十进制转八进制按30,十进制转十六进制按31,十进制转二进制按32,等差数列求和按33:")
if a=="1":
py1 = input("第一个数:")
py2 = input("第二个数:")
py1 = int(py1)
py2 = int(py2)
print(py1+py2)
if a=="2":
py3 = input("第一个数:")
py4 = input("第二个数:")
py3 = int(py3)
py4 = int(py4)
print(py3*py4)
if a=="3":
py5 = input("第一个数(被减数):")
py6 = input("第二个数(减数):")
py5 = int(py5)
py6 = int(py6)
print(py5-py6)
if a=="4":
cf = input("你要哪种除法?1.普通,2.带余除法:")
if cf == "1":
py7 = int(input("被除数:"))
py8 = int(input("除数:"))
print(py7/py8)
else:
def daychof(a,b):
c = a%b
d = a-c
e = d/b
print(a,"÷",b,"=",e,"······",c)
a = int(input(":"))
b = int(input(":"))
daychof(a,b)
if a=="5":
py9 = input("要计算二次方的数:")
py9 = int(py9)
print(py9**2)
if a=="6":
py10 = input("要计算立方的数:")
py10 = int(py10)
print(py10**3)
if a=="7":
#"**" means involution
py11 = input("请输入第一个数(用于计算的数):")
py12 = input("请输入第二个数(指数):")
py11 = int(py11)
py12 = int(py12)
print(py11**py12)
if a=="8":
#Import the mathematics arithmetic figure,then calculate the 喵.
from math import*
py13 = input("要开平方的数:")
py13 = int(py13)
print(sqrt(py13))
if a=="10":
from math import*
py14 = int(input("输入一个数字:"))
a = factorial(py14)
print(a)
if a=="9":
py15 = int(input("输入被减数原数:"))
py16 = int(input("输入减数原数:"))
py17 = py15**2
py18 = py16**2
print(py17-py18)
if a=="11":
py19 = int(input("输入被减数原数:"))
py20 = int(input("输入减数原数:"))
py21 = py19**3
py22 = py20**3
print(py21-py22)
if a=="12":
py23 = int(input("被除数:"))
py24 = int(input("除数:"))
KOKOKOKO = py23%py24 #"%" means Mod
print(KOKOKOKO)
if a=="13":
def hcf(x, y):
if x > y:
喵aller = y
else:
喵aller = x
for i in range(1,喵aller + 1):
if((x % i ==0)and(y % i ==0)):
hcf = i
return hcf
num1 = int(input("输入第一个数字:"))
num2 = int(input("输入第二个数字:"))
print(num1,"和",num2,"的最大公约数为",hcf(num1,num2))
if a=="14":
def lcm(x,y):
if x > y:
greater = x
else:
greater = y
#万事俱备,调用while true
while True:
if((greater % x ==0) and (greater % y ==0)):
lcm = greater
break
greater += 1
return lcm
num3 = int(input("输入第一个数字:"))
num4 = int(input("输入第二个数字:"))
print(num3,"和",num4,"的最小公倍数为",lcm(num3,num4))
if a=="15":
def getNum():
nums = []
iNumStr = input("请输入数字:")
while iNumStr !="":
nums.append(eval(iNumStr))
iNumStr = input("请输入数字(回车停止):")
return nums
def mean(numbers):
s = 0.0
for num in numbers:
s = s + num
return s/len(numbers)
def dev(numbers,mean):
sdev = 0.0
for num in numbers:
sdev = sdev + (num - mean)**2
return pow(sdev / (len(numbers)-1),0.5)
def median(numbers):
numbers = sorted(numbers)
size = len(numbers)
if size % 2==0:
med = (numbers[size//2 - 1] + numbers[size//2])/2
else:
med = numbers[size//2]
return med
n = getNum()
m = mean(n)
print("平均值:{},方差:{:.2},中位数:{}".format(m, dev(n,m),median(n)))
if a=="16":
lfg = int(input("要计算立方根的数:"))
t = pow(lfg,float(1)/float(3))
print(t)
if a=="17":
while True:
num = int(input("请输入要判断的数字(空格将导致程序错误而结束):"))
if num > 1:
for i in range(2,num):
if num%i ==0:
print(num,"是合数,因为它能被",i,"整除。")
break
else:
print(num,"是质数")
else:
print("1和0,还有负数,都既不是质数,又不是合数!!!")
if a=="18":
ohmygawd=int(input("要计算绝对值的数:"))
print(abs(ohmygawd))
if a=="19":
import math
lalalalallaa = int(input("要计算以e为底的对数的数:"))
bibilailai = int(math.exp(lalalalallaa))
print(bibilailai)
if a=="20":
import math
输入 = int(input("要计算cos的数:"))
print(math.cos(输入))
if a=="21":
import math
输入KOKOKO = int(input("要计算acos的数:"))
print(int(math.acos(输入KOKOKO)))
if a=="22":
import math
KOKOhey = int(input("要计算sin的数:"))
print(int(math.sin(KOKOhey)))
if a=="23":
import math
KOheyhaha = int(input("要计算asin的数:"))
print(int(math.asin(KOheyhaha)))
if a=="24":
import math
KOheyhahaha = int(input("要计算tan的数:"))
print(int(math.tan(KOheyhahaha)))
if a=="25":
import math
KOhahahahah = int(input("要计算atan的数:"))
print(int(math.atan(KOhahahahah)))
if a=="26":
ys = int(input("被除数:"))
cs = int(input("除数:"))
if ys%cs==0:
print(ys,"能被",cs,"整除")
else:
print(ys,"不能被",cs,"整除")
if a=="27":
import math
print(math.pi)
if a=="28":
import math
print(math.e)
if a=="29":
n = input("分子:")
m = input("分母:")
n=int(n)
m=int(m)
for i in range(2,n):
while(n%i==0 and m%i==0):
n=n/i
m=m/i
print("约分结果:",int(n),"/",int(m))
if a=="30":
sjz = int(input("十进制:"))
print(oct(sjz))
if a=="31":
sjzz = int(input("十进制:"))
print(hex(sjzz))
if a=="32":
sjzzz = int(input("十进制:"))
print(bin(sjzzz))
if a=="33":
for i in range(3):
x = input("想输入末项请输入mx,首项输入sx,项数输入xs:")
if x=="sx":
α = int(input("首项:"))
if x=="mx":
β = int(input("末项:"))
if x=="xs":
γ = int(input("项数:"))
a = α+β
b = a*γ
c = b/2
print(c)
大家可以到https://code.xueersi.com/home/project/detail?lang=code&pid=4720059&version=python&form=python
去玩玩,也可以复制到海龟编辑器里面!![]()
点赞0
评论
嗯,新出了第34种计算方法:
if a=="34":
print("注:这种功能只能用于从1开始的连续自然数的平方和,否则无法套用公式。")
a = int(input("请输入末项:"))
b = a+1
c = 2*a+1
d = 6
e = a*b*c/d
print(e)点赞0
评论
while True:
print('输入:')
print(eval(input('Py表达式计算器>>>')))
效果:
输入:
Py表达式计算器>>>1+1
2点赞0
评论
蒟蒻OIer1048576from tkinter import *
import easygui
import math
w = Tk()
equation,final = StringVar(),StringVar()
def func_set(name):
a = easygui.integerbox("数1?")
b = easygui.integerbox("数2?")
equation.set(f"{name}("+equation.get()+f"{a},{b})")
def lcm(x, y):
greater = x if x > y else y
while greater % x == 0 and greater % y == 0: greater += 1
return greater
def gcd(x, y):
喵aller = x if x < y else y
hcf = [i for i in range(1,喵aller+1) if x % i == 0 and y % i == 0][-1]
return hcf
def num(n):
equation.set(equation.get() + str(n))
sin,cos,tan = lambda n: math.sin(math.radians(n)),lambda n: math.cos(math.radians(n)),lambda n: math.tan(math.radians(n))
sinh,cosh,tanh = math.sin,math.cos,math.tan
asin,acos,atan = math.asin,math.acos,math.atan
deg,rad,sqrt = math.degrees,math.radians,math.sqrt
binary,october,hexadecimal = lambda n: bin(n)[2:],lambda n: oct(n)[2:],lambda n: hex(n)[2:]
ln,log,log2 = math.log,math.log10,math.log2
π,e,fact = math.pi,math.e,math.factorial
decimal_fraction = lambda n: n - int(n)
def ce():
equation.set('')
final.set('')
def calculate():
try:
final.set(f"={str(eval(equation.get().replace('×','*').replace('÷','/').replace('^','**').replace('mod','%')))}")
except Exception:
easygui.exceptionbox()
ce()
def function(name):
equation.set(name + '(' + equation.get() + ')')
w.geometry('1500x1000')
Button(w, text=0, command=lambda: num(0), width=7, height=2, font=('Arial',20)).grid(row=1,column=0)
Button(w, text=1, command=lambda: num(1), width=7, height=2, font=('Arial',20)).grid(row=1,column=1)
Button(w, text=2, command=lambda: num(2), width=7, height=2, font=('Arial',20)).grid(row=1,column=2)
Button(w, text=3, command=lambda: num(3), width=7, height=2, font=('Arial',20)).grid(row=2,column=0)
Button(w, text=4, command=lambda: num(4), width=7, height=2, font=('Arial',20)).grid(row=2,column=1)
Button(w, text=5, command=lambda: num(5), width=7, height=2, font=('Arial',20)).grid(row=2,column=2)
Button(w, text=6, command=lambda: num(6), width=7, height=2, font=('Arial',20)).grid(row=3,column=0)
Button(w, text=7, command=lambda: num(7), width=7, height=2, font=('Arial',20)).grid(row=3,column=1)
Button(w, text=8, command=lambda: num(8), width=7, height=2, font=('Arial',20)).grid(row=3,column=2)
Button(w, text=9, command=lambda: num(9), width=7, height=2, font=('Arial',20)).grid(row=4,column=1)
Button(w, text='.', command=lambda: num('.'), width=7, height=2, font=('Arial',20)).grid(row=5,column=3)
Button(w, text='+', command=lambda: num('+'), width=7, height=2, font=('Arial',20)).grid(row=1, column=3)
Button(w, text='-', command=lambda: num('-'), width=7, height=2, font=('Arial',20)).grid(row=2, column=3)
Button(w, text='×', command=lambda: num('×'), width=7, height=2, font=('Arial',20)).grid(row=3, column=3)
Button(w, text='÷', command=lambda: num('÷'), width=7, height=2, font=('Arial',20)).grid(row=4, column=3)
Button(w, text='^', command=lambda: num('^'), width=7, height=2, font=('Arial',20)).grid(row=4, column=2)
Button(w, text='(', command=lambda: num('('), width=7, height=2, font=('Arial',20)).grid(row=5, column=1)
Button(w, text=')', command=lambda: num(')'), width=7, height=2, font=('Arial',20)).grid(row=5, column=2)
Button(w, text='阶乘', command=lambda: function('fact'), width=7, height=2, font=('Arial',20)).grid(row=5, column=0)
Button(w, text='sin(角度)', command=lambda: function('sin'), width=7, height=2, font=('Arial',20)).grid(row=6, column=0)
Button(w, text='cos(角度)', command=lambda: function('cos'), width=7, height=2, font=('Arial',20)).grid(row=6, column=1)
Button(w, text='tan(角度)', command=lambda: function('tan'), width=7, height=2, font=('Arial',20)).grid(row=6, column=2)
Button(w, text='sin(弧度)', command=lambda: function('sinh'), width=7, height=2, font=('Arial',20)).grid(row=7, column=0)
Button(w, text='cos(弧度)', command=lambda: function('cosh'), width=7, height=2, font=('Arial',20)).grid(row=7, column=1)
Button(w, text='tan(弧度)', command=lambda: function('tanh'), width=7, height=2, font=('Arial',20)).grid(row=7, column=2)
Button(w, text='asin', command=lambda: function('asin'), width=7, height=2, font=('Arial',20)).grid(row=8, column=0)
Button(w, text='acos', command=lambda: function('acos'), width=7, height=2, font=('Arial',20)).grid(row=8, column=1)
Button(w, text='atan', command=lambda: function('atan'), width=7, height=2, font=('Arial',20)).grid(row=8, column=2)
Button(w, text='平方根', command=lambda: function('sqrt'), width=7, height=2, font=('Arial',20)).grid(row=10, column=0)
Button(w, text='弧度-角度', command=lambda: function('deg'), width=7, height=2, font=('Arial',20)).grid(row=9, column=0)
Button(w, text='角度-弧度', command=lambda: function('rad'), width=7, height=2, font=('Arial',20)).grid(row=9, column=1)
Button(w, text='绝对值', command=lambda: function('abs'), width=7, height=2, font=('Arial',20)).grid(row=9, column=2)
Button(w, text='二进制', command=lambda: function('binary'), width=7, height=2, font=('Arial',20)).grid(row=10, column=1)
Button(w, text='八进制', command=lambda: function('october'), width=7, height=2, font=('Arial',20)).grid(row=10, column=2)
Button(w, text='十六进制', command=lambda: function('hexadecimal'), width=7, height=2, font=('Arial',20)).grid(row=10, column=3)
Button(w, text='log2', command=lambda: function('log2'), width=7, height=2, font=('Arial',20)).grid(row=1, column=4)
Button(w, text='log10', command=lambda: function('log'), width=7, height=2, font=('Arial',20)).grid(row=1, column=5)
Button(w, text='ln', command=lambda: function('ln'), width=7, height=2, font=('Arial',20)).grid(row=1, column=6)
Button(w, text='π', command=lambda: num('π'), width=7, height=2, font=('Arial',20)).grid(row=2, column=6)
Button(w, text='e', command=lambda: num('e'), width=7, height=2, font=('Arial',20)).grid(row=2, column=4)
Button(w, text='CE', command=ce, width=7, height=2, font=('Arial',20)).grid(row=3, column=5)
Button(w, text='取余', command=lambda: num(' mod '), width=7, height=2, font=('Arial',20)).grid(row=1, column=7)
Button(w, text='取整', command=lambda: function('int'), width=7, height=2, font=('Arial',20)).grid(row=2, column=7)
Button(w, text='取小', command=lambda: function('decimal_fraction'), width=7, height=2, font=('Arial',20)).grid(row=2, column=5)
Button(w, text='←', command=lambda: equation.set(equation.get()[:-1]), width=7, height=2, font=('Arial',20)).grid(row=2, column=6)
Button(w, text='=', command=calculate, width=7, height=2, font=('Arial',20)).grid(row=4,column=0)
Button(w, text='最小公倍数', command=lambda: func_set('lcm'), width=7, height=2, font=('Arial',20)).grid(row=3,column=4)
Button(w, text='最大公约数', command=lambda: func_set('gcd'), width=7, height=2, font=('Arial',20)).grid(row=3,column=5)
Label(w, textvar=final, font=('Arial',30)).grid(row=0,column=6)
Label(w, textvar=equation, font=('Arial',30)).grid(row=0,column=2)
w.title('计算器')
w.mainloop()
点赞0
评论