# 四则运算生成器

import randomdef Subject_Creater():    i = 0    a = 0    b = 0    print "How many questions do you want to test ?"    n = input()    while i<n :     # 随机生成的题目数量为用户输入的数        x = round(random.uniform(0,10),2)        y = round(random.uniform(0,10),2)        z = random.choice("+-*/")        if z == "+":            result = round(x+y,2)            print x, z, y, "="        elif z == "-":            result = round(x-y,2)            print x, z, y, "="        elif z == "*":            result = round(x*y,2)            print x, "×", y, "="        else :            if y == 0:                i -= 1            else:                result = round(x/y,2)            print x, "÷", y, "="        temp = input()        if result == temp:         # 用于记录正确和错误答题数以便给出成绩            print "Ture"            a += 1.0        else:            print "False ! The truth answer is:",result            b += 1.0        i += 1    print "Your grade is :",round(a/(a+b)*100,2)Subject_Creater()

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

posted @ 2017-02-28 21:20  蚂蚁有毒  阅读(328)  评论(11编辑  收藏  举报