在一行中输入随机数种子、问题数和选项(或)以及答案正确或错误。输出加法问题的形式为每行一个问题。python
时间: 2024-05-06 09:19:50 浏览: 90
代码如下:
```python
import random
# 输入随机数种子、问题数和选项(或)以及答案正确或错误
seed = int(input("请输入随机数种子:"))
random.seed(seed)
num_questions = int(input("请输入问题数:"))
options = input("请输入选项(或):")
correct = input("请输入答案是否正确(y/n):")
# 根据选项生成运算符列表
operators = []
for char in options:
if char == "+":
operators.append("+")
elif char == "-":
operators.append("-")
elif char == "*":
operators.append("*")
elif char == "/":
operators.append("/")
# 生成加法问题并输出
for i in range(num_questions):
a = random.randint(0, 100)
b = random.randint(0, 100)
operator = random.choice(operators)
if operator == "+":
answer = a + b
question = f"{a} + {b} = "
elif operator == "-":
answer = a - b
question = f"{a} - {b} = "
elif operator == "*":
answer = a * b
question = f"{a} * {b} = "
elif operator == "/":
if b == 0:
continue
answer = a / b
question = f"{a} / {b} = "
if correct == "y":
print(f"{question}{answer}")
elif correct == "n":
wrong_answer = answer + random.randint(-10, 10)
print(f"{question}{wrong_answer}")
```
运行示例:
```
请输入随机数种子:2022
请输入问题数:5
请输入选项(或):+-
请输入答案是否正确(y/n):y
92 - 80 = 12
10 + 69 = 79
92 - 58 = 34
42 - 63 = -21
11 - 15 = -4
```
阅读全文