答案没隐藏起来答案没隐藏起来答案没隐藏起来
而二维
。。。。
本帖最后由 1140522290 于 2017-7-26 17:02 编辑
import random
def create_equation():
#随机生成2个常数
a = random.randint(1,10)
b = random.randint(1,10)
#随机生成运算法则
sfl = ("+","-","*","/")
sf = random.choice(sfl)
#生成等式
ds = str(a)+str(sf)+str(b)
#计算结果
if sf == "+" :
jg = a+b
elif sf == "-":
jg = a-b
elif sf == "*":
jg = a*b
else :
jg = a/b
#返回结果
c = 'x'+ str(sf) +str(b)+ '=' + str(jg)
fh={'xsf':c , 'k' : a}
return fh
dsj = create_equation()
p = dsj.get("xsf")
print(p)
daan = int(input("你的答案是:"))
if daan == dsj.get("k"):
print("回答正确")
else :
print("回答错误,正确答案是:"+ str(dsj.get("k")))
初步弄出来了,测试成功!
使用字典返回,调用结果老错,后来发现,应该是在函数的基础上直接调用字典,会重新运行一次函数。
import math
def quadratic(a,b,c):
if not isinstance(a,(int,float)):
raise TypeError('a is not a number')
if not isinstance(b,(int,float)):
raise TypeError('b is not a number')
if not isinstance(c,(int,float)):
raise TypeError('c is not a number')
d=b*b-4*a*c
if a==0:
if b==0:
if c==0:
return '方程根为全体实数'
else:
return '方程无根'
else:
x1=-c/b
x2=x1
return x1,x2
else:
if d<0:
return '方程无根'
else:
x1 = (-b + math.sqrt(d))/2/a
x2 = (-b - math.sqrt(d))/2/a
return x1,x2
print(quadratic(2,3,1))
print(quadratic(1,3,-4)
看看鱼油们的想法
楼主,你是一个大好人!!
新手初来乍到,各路大神请多多关照{:5_92:}
import random
def create_equation():
return "equation1:y = %dx + %d\nequation2:y = %dx + %d" % tuple(random.sample(,4))
print(create_equation())
我也想试试
import random
x = int(input('请输入方程方程系数范围:'))
list1 =
a,b = random.sample(list1,2)
print('随机方程为:', '%dx + %d = 0' % (a,b))
qq
英语完形填空的出题方式,先写完整等式,再把答案抠出来···
涉及小数就要用约等于,这里为了偷懒就不搞小数了
import random
def create_equation():
# 用 Ax+By=C 的形式,需要随机:答案2个,系数4个,系数矩阵线性相关的时候条件不足解
a = # 系数和答案范围
result_1 = eval("%s*%s + %s*%s" %(a,a,a,a))
result_2 = eval("%s*%s + %s*%s" %(a,a,a,a))
print("%s*x + %s*y = %s" %(a,a,result_1))
print("%s*x + %s*y = %s" %(a,a,result_2))
return a #答案 x,y
import random
def create_equation():
a = random.randint(1, 200)
b = random.randint(1, 200)
c = random.randint(1, 200)
return str(a)+random.choice([' × ',' ÷ '])+' a '+random.choice([' + ',' - '])+str(b)+' = '+str(c)
for i in range(5):
print(create_equation())
## 130 ×a+ 38 = 38
## 49 ÷a- 192 = 90
## 128 ÷a- 23 = 139
## 161 ×a- 31 = 140
## 114 ÷a- 85 = 19
1
看看
{:5_95:}
本帖最后由 咕咕鸡鸽鸽 于 2019-1-15 11:53 编辑
围观大佬
from random import *
def fun68():
return str(randint(1,10)) + "x + " + str(randint(1,10)) + "y =" + str(randint(10,20)) + "\n" +\
str(randint(1,10)) + "x + " + str(randint(1,10)) + "y =" + str(randint(10,20))
print(fun68())
学习学习
{:10_243:}前几from random import randint as rt
def create_equation():
a = rt(1,100)
b = rt(1,100)
x = rt(1,100)
answer = a*x+b
return '{} * x +{} = {}'.format(a,b,x)
print(create_equation())次的题做的要自闭了
1