代码如下:
import random
from fractions import Fraction
operation = ['+', '-', '*', '/'] #四则运算的符号
global f
global s
s=0
def score(): #整数题目生成函数
global s
op = ['+', '-']
number = random.randint(1, 3)
f = ''
for i in range(number):
a = random.randint(1, 10)
b = random.randint(a, 10)
rand = op[random.randint(0, 1)]
f += str(a) + '/'+ str(b)+rand
a = random.randint(1, 10)
b = random.randint(a, 10)
f += str(a) + '/'+ str(b)
n = eval(f)
n = Fraction('{}'.format(n)).limit_denominator()
if n > 0:
print('题目:')
print(f,'=')
print('请输出答案&