📅  最后修改于: 2023-12-03 14:57:48.453000             🧑  作者: Mango
本程序是一个测试用户的数学算术能力的小工具,其中包含了一系列的计算题目,用户需要在规定时间内完成这些任务。程序将根据用户所能完成的题目数量和正确率来评估用户的数学算术能力水平。
def arithmetic_ability():
# 设置题目数量
problem_num = int(input("请输入题目数量:"))
# 设置难度等级
difficulty = int(input("请输入难度等级:(1表示简单,2表示中等,3表示困难)"))
correct_num = 0
wrong_num = 0
# 生成随机数
for i in range(problem_num):
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
operator = random.choice(["+", "-", "*", "/"])
if difficulty == 1:
while True:
if operator == "-" and num1 < num2:
num1, num2 = num2, num1
elif operator == "/" and num1 % num2 != 0:
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
else:
break
elif difficulty == 2:
num1 = random.randint(50, 300)
num2 = random.randint(1, 50)
else:
num1 = random.randint(100, 1000)
num2 = random.randint(50, 100)
problem = str(num1) + operator + str(num2) + "="
try:
answer = float(input(problem))
if operator == "+":
temp = num1 + num2
elif operator == "-":
temp = num1 - num2
elif operator == "*":
temp = num1 * num2
else:
temp = num1 / num2
if abs(answer - temp) < 1e-4:
correct_num += 1
else:
wrong_num += 1
except ValueError:
print("输入有误,请重新输入")
print("\n已完成所有计算题目")
print("正确数量:", correct_num)
print("错误数量:", wrong_num)
accuracy = correct_num / problem_num
if accuracy < 0.6:
print("你的数学算术能力相对较弱")
elif 0.6 <= accuracy < 0.8:
print("你的数学算术能力一般")
else:
print("你的数学算术能力较为强")