import random
def generate_question():
operator = random,choice(['+','-'])
num1 = random.randint(1,20)
num2 = random.randint(1,20)
if operator == '+':
answer = num1 + num2
else:
answer = num1 - num2
question = f"{num1} {operator} {num2} ="
return question, answer
for i in range(10):
question,answer = generate_question()
print(question)
软件工程随机生成加减法(python)
发布时间 2023-09-12 10:57:18作者: lm9856