import random |
print ( "小学四则运算测试(输入8888结束):" ) |
ops = [ '+' , '-' , '*' , '/' ] |
ans = "" |
i = 1 |
while ans ! = "8888" : |
add1 = random.randint ( 5 , 50 ) |
add2 = random.randint ( 5 , 50 ) |
op = random.randint( 0 , 3 ) |
eq = str (add1) + ops[op] + str (add2) |
val = eval (eq) |
print ( "第%d题: %s=" % (i,eq) ) |
ans = input ( "请答题,把正确答案写在其后: " ) |
if ans = = '8888' : |
break |
elif val = = int (ans): |
print ( "你牛,你的回答正确!" ) |
else : |
print ( "对不起,你的回答错误!正确答案是: %d" % val) |
i = i + 1 |
print () |