参考代码博客园链接(https://www.cnblogs.com/shi1/p/8670776.htm)
def createarithmetic(self):
list = []
f1 = function1.function1()
f2 = function2()
operator_no = random.randint(1,3)
if operator_no == 1:
list.append(f1.createNum())
list.append(f2.createOperator())
list.append(f1.createNum())
elif operator_no == 2:
start = random.randint(0,2)
end = 0
if start == 0:
end == 0
else:
end = start +1
for i in range(1,4):
if i == start:
list.append("(")
list.append(f1.createNum())
if i == end:
list.append(")")
list.append(f2.createOperator())
list.pop()
elif operator_no == 3:
start = random.randint(0, 3)
end = 0
if start == 0:
end == 0
else:
end = start + 1 + random.randint(0,1)
if end >= 4:
end=4
for i in range(1, 5):
if i == start:
list.append("(")
list.append(f1.createNum())
if i == end:
list.append(")")
list.append(f2.createOperator())
list.pop()
else:
list.append(f1.createNum())
list.append(f2.createOperator())
list.append(f1.createNum())
return list
相关文章
- 12-15四则运算生成器
- 12-15四则运算个人工作流程,计应193,第三组,刘晨龙
- 12-15小学生四则运算出题系统——计应193许颖然
- 12-15四则运算1
- 12-15四则运算计算机C++项目练习
- 12-15随机生成四则运算题
- 12-15四则运算--计应192陈涯涯
- 12-15计应193张跃 四则运算系统
- 12-15出30道四则运算题目
- 12-15打印四则运算题目的“软件”