import random
# 加法
n = 10
list1 = []
while n > 0:
a = random.randint(0, 100)
b = random.randint(0, 100)
e = "{}+{}=".format(a, b)
if a + b <= 100 and e not in list1:
list1.append(e)
n -= 1
print(e)
# 减法
n = 10
list2 = []
while n > 0:
c = random.randint(0, 100)
d = random.randint(0, 100)
f = "{}-{}=".format(c, d)
if c >= d and f not in list2:
list2.append(f)
n -= 1
print(f)
# 乘法
n = 5
list3 = []
while n > 0:
c = random.randint(1, 9)
d = random.randint(1, 9)
f = "{}*{}=".format(c, d)
if c >= d and f not in list3:
list3.append(f)
n -= 1
print(f)
执行结果:
暑假给宝宝布置的了家庭作业是每天做20道100以内加减法。每天出题都要想数字比较麻烦。就写了个代码,每天执行出结果把题发给宝宝外婆。感觉还挺好用的。另外还有5道乘法口诀题。