python加法练习题

设计一个程序,帮助小学生练习10以内的加法

详情:

 随机生成加法题目

学生查看题目并输入答案

判别学生答题是否正确

退出时,统计学生答题总数,正确数量及正确率(保留两位小数点)

import random
correct = 0
worry = 0
ti = 0
while True:
    a = random.randint(1,10)
    b = random.randint(1,10)
    print("%d+%d=" %(a,b))
    ti += 1
    d=input()
    c = a + b
    if d == "exit":
        break
    elif  c == int(d):
        correct += 1
        print("正确")
    else:
        worry += 1
        print("错误")
e = (float(correct)/float(ti))*100
print("答题总数为%d,正确数为%d,正确率为%.2f%%" %(ti,correct,e))

猜你喜欢

转载自blog.csdn.net/zcx1203/article/details/81546412