用python给我家小子搞点算术题做。。。

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值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jamelee

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值