编写一个100以内的整数加减乘除练习器
时间: 2024-02-16 17:04:46 浏览: 143
100以内算数练习器
好的,我可以为您提供一个简单的Python程序,可以让您练习100以内的整数加减乘除。
```python
import random
def generate_question():
"""生成随机的加减乘除算式"""
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
operator = random.choice(['+', '-', '*', '/'])
if operator == '+':
answer = num1 + num2
elif operator == '-':
answer = num1 - num2
elif operator == '*':
answer = num1 * num2
else:
# 除法操作时需要保证能够整除
answer = num1 // num2
num1 = answer * num2
question = f"{num1} {operator} {num2} = "
return question, answer
def main():
"""主函数,用于运行练习器"""
print("欢迎使用100以内的整数加减乘除练习器!")
print("请输入您要练习的题目数量:")
num_questions = int(input())
correct_answers = 0
for i in range(num_questions):
question, answer = generate_question()
print(f"第{i+1}题:{question}")
user_answer = int(input())
if user_answer == answer:
print("回答正确!")
correct_answers += 1
else:
print(f"回答错误,正确答案为{answer}")
print(f"您一共回答了{num_questions}道题,其中{correct_answers}道题回答正确。")
if __name__ == '__main__':
main()
```
这个程序会生成随机的加减乘除算式,让您输入答案,然后判断您的答案是否正确。您可以输入练习题目的数量,程序会自动生成相应数量的练习题目。祝您练习愉快!
阅读全文