代码:
import random
count = 0
right = 0
num = int(input("请输入题库数目:"))
print("那么就开始做题吧!(注意小数取整数部分)")
print("")
while count<num:
op = ["+", "-", "*", "/"]
s = random.choice(op)
a = random.randint(0,100)
b = random.randint(1,100)
print("%d %s %d" % (a, s, b))
question = input("请输入答案:(按q退出)")
if question == 'q' :
break
elif len(question) == 0:
count+=1
continue
if s == '+':
if int(question) == (a+b) :
print("正确了!")
right+=1
else:
print("错了!")
if s == '-':
if int(question) == (a-b) :
print("正确了!")
right+=1
else:
print("错了!")
if s == '*':
if int(question) == (a*b) :
print("正确了!")
right+=1
else:
print("错了!")
if s == '/':
if int(question) == (a/b) :
print("正确了!")
right+=1
else:
print("错了!")
count+=1
print("")
print("你一共几算了%d道题目,做对%d道,做错%d道,继续努力!" % (count, right, (count-right)))