给小学僧一年级做的一个加减法出题器,要求是两个数加减,其中一个数为一位数,且结果不能为负。
可打包为exe
from random import randint,shuffle
lst= []
x = int(input("请输入多少以内:"))
y = int(input("请输入题目数量:"))
while True:
a = randint(0,x)
b = randint(0,x)
c = randint(0,x)
d = randint(0,x)
if a + b < x and (a < 10 or b < 10):
lst.append(str(a)+'+'+str(b)+'=( )')
if 0 < c - d < x and (c < 10 or d < 10):
lst.append(str(c)+'-'+str(d)+'=( )')
if len(lst)==y:
break
out=open('test.txt','w')
shuffle(lst)
for i in lst:
out.write(i + '\n')
out.close()