四则运算

参考代码博客园链接(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

代码运行结果

四则运算
四则运算

上一篇:2021-12-17_学习B站Java基础视频_IO流(File概述)


下一篇:【JAVA黑马程序员笔记】三P233-P312(List、Set、比较器、泛型、Map、File、IO流...)