Python编写一个10以内加减法自动出题程序
时间: 2024-09-12 07:04:00 浏览: 76
混合加减法出题程序python
当然可以。Python编写一个简单的10以内加减法自动出题程序,我们可以利用随机数生成功能来实现。这里是一个基本的示例:
```python
import random
def generate_question(operation):
num1 = random.randint(1, 10)
num2 = random.randint(1, 10)
if operation == 'add':
answer = num1 + num2
question = f"10以内{operation}题:{num1} + {num2} = ?"
elif operation == 'subtract':
while num1 >= num2:
num2 = random.randint(1, 10)
answer = num1 - num2
question = f"10以内{operation}题:{num1} - {num2} = ?"
return question, answer
# 出5道加法题和5道减法题
for _ in range(5):
print(generate_question('add'))
for _ in range(5):
print(generate_question('subtract'))
阅读全文