import random
file=open("./mathhomework.txt",mode="a+")
i=1
while i<=300:
x4=int((random.random()+3)*10) #30~40随机数
x3=int((random.random()+2)*10) #20~30随机数
x2=int((random.random()+1)*10) #10~20随机数
x1=int((random.random())*10) #0~10随机数
x01=int((random.random())*5) #0~5随机数
opr1=int((random.random())*2) #0~1随机数
opr2=int((random.random())*2) #0~1随机数
if(opr1==0): #控制opr1运算符
opr1str="+"
else:
opr1str="-"
if(opr2==0): #控制opr2运算符
opr2str="+"
else:
opr2str="-"
print(str(x2)+opr1str+str(x1)+opr2str+str(x01)+"="+" " + str(x3)+opr1str+str(x1)+opr2str+str(x01)+"="+" " + str(x3)+opr1str+str(x2)+opr2str+str(x01)+"="+" " + str(x3)+opr1str+str(x2)+opr2str+str(x1)+"="+" ")
#算术组合:210、310、320、321
file.write(str(x2)+opr1str+str(x1)+opr2str+str(x01)+"="+" " + str(x3)+opr1str+str(x1)+opr2str+str(x01)+"="+" " + str(x3)+opr1str+str(x2)+opr2str+str(x01)+"="+" " + str(x3)+opr1str+str(x2)+opr2str+str(x1)+"="+" "+"\n")
file.flush()
print(str(x2)+opr1str+str(x01)+opr2str+str(x1)+"="+" " + str(x3)+opr1str+str(x01)+opr2str+str(x1)+"="+" " + str(x3)+opr1str+str(x01)+opr2str+str(x2)+"="+" " + str(x3)+opr1str+str(x1)+opr2str+str(x2)+"="+" ")
#算术组合:201、301、302、312
file.write(str(x2)+opr1str+str(x01)+opr2str+str(x1)+"="+" " + str(x3)+opr1str+str(x01)+opr2str+str(x1)+"="+" " + str(x3)+opr1str+str(x01)+opr2str+str(x2)+"="+" " + str(x3)+opr1str+str(x1)+opr2str+str(x2)+"="+" "+"\n")
file.flush()
if i%15==0: #分隔符:2*15行一个分割,每天做30道题
print("=======================================================================")
file.write("=================================================================="+"\n")
file.flush()
i+=1
while 1:
if(x1==0):
x1=int((random.random())*10)
continue
if(x01==0):
x01=int((random.random())*5)
continue
if(x01==x1):
x1=int((random.random())*10)
x01=int((random.random())*5)
continue
else:
break
#添加过滤条件,避免生成0值