1. import random
2. target_list = ["+","-","*","/"]
3. True_list = []
4. answer_list = []
5. temp_list =[]
6. chr_dic = {}
7. while True:
8. num_1 = random.randint(0,10)
9. num_2 = random.randint(0,10)
10. num_3 = random.randint(0,3)
11. sign = target_list[num_3]
12. answer = input("{0}{1}{2}=".format(num_1,sign,num_2))
13. if answer == "n":
14. break
15. else:
16. count = 1
17. try:
18. float(answer)
19. except ValueError:
20. y_n = input("输入错误,是否继续(y/n)?")
21. if y_n == "n":
22. break
23. else:
24. continue
25. else:
26. answer_list.append(answer)
27. True_list.append(round(eval(f"{num_1}{sign}{num_2}"),2))
28. Calculations = "{0}{1}{2}={3}".format(num_1,sign,num_2,answer)
29. temp_list.append(Calculations)
30. Accuracy_rate = 0
31. Accuracy = 0
32. for i in range(0,len(answer_list)):
33. if int(answer_list[i]) == True_list[i]:
34. Accuracy += 1
35. chr_dic[temp_list[i]] = "正确"
36. else:
37. chr_dic[temp_list[i]] = "错误"
38. Accuracy_rate = round(Accuracy/len(answer_list),2)
39. print("正确率:",Accuracy_rate)
40. for i in range(0,len(list(chr_dic.keys()))):
41. print(list(chr_dic.keys())[i]," ",list(chr_dic.values())[i])