编写一个100以内的整数加减乘除练习器
时间: 2024-03-07 10:46:26 浏览: 30
好的,我可以帮您编写一个100以内的整数加减乘除练习器。以下是Python代码实现:
```python
import random
operators = ['+', '-', '*', '/']
while True:
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
operator = random.choice(operators)
if operator == '+':
result = num1 + num2
elif operator == '-':
result = num1 - num2
elif operator == '*':
result = num1 * num2
elif operator == '/':
result = num1 // num2
answer = input(f"What is {num1} {operator} {num2}? ")
if answer == 'exit':
break
if int(answer) == result:
print("Correct!")
else:
print(f"Wrong! The answer is {result}.")
```
这个程序会在每次运行时随机生成两个1到100之间的整数和一个加减乘除运算符,并要求用户输入计算结果。如果用户输入了正确的答案,则输出“Correct!”,否则输出正确答案。如果用户输入“exit”,则程序退出。
阅读全文