重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#定义函数
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、网站空间、营销软件、网站建设、湖北网站维护、网站推广。
class myCalc:
def __init__(self,a,b):
self.a=a
self.b=b
def addition(self,Retain):
return round(self.a + self.b ,Retain)
def subtraction(self,Retain):
return round(self.a - self.b,Retain)
def multiplication(self,Retain):
return round(self.a * self.b,Retain)
def division(self,Retain):
return round(self.a / self.b,Retain)
while True:
get_num1 = input("请输入第一个数字:")
opera = input("请输入运算符:")
get_num2 = input("请输入第二个数字:")
get_retain = input("请输入保留小数位数:")
num1 = float(get_num1)
num2 = float(get_num2)
retain = int(get_retain)
result = 0.00
if opera == "+":
result = myCalc(num1,num2).addition(retain)
elif opera == "-":
result = myCalc(num1,num2).subtraction(retain)
elif opera == "*":
result = myCalc(num1,num2).multiplication(retain)
else:
result = myCalc(num1,num2).division(retain)
print("输出结果是:",result)
import random
max_n = 100
i = 0
while True:
i += 1
# 随机运算,0+,1-
op = random.randint(0, 1)
# +
if op == 0:
x1 = random.randint(0, max_n)
x2 = random.randint(0, max_n - x1)
result = x1 + x2
qst = str(x1) + "+" + str(x2) + "="
question = [qst, result]
# -
elif op == 1:
x1 = random.randint(0, max_n)
x2 = random.randint(0, x1)
result = x1 - x2
qst = str(x1) + "-" + str(x2) + "="
question = [qst, result]
x = input("第{:2d}题:{}".format(i + 1, question[0]))
if int(x) == int(question[1]):
print("回答正确!")
else:
print("回答错误!{}{}".format(question[0], question[1]))
def add(a,b):#加法运算return a+bdef sub(a,b):#减法运算return a-bdef mul(a,b):#乘法运算return a*bdef div(a,b=1):#除法运算return a/b