在上次的基础上,我加了一点点东西

#Python代码
from random import *
from time import *
fuhao = input('1-加法,2-乘法,3-复数')
if fuhao != '3':
    n = int(input('位数>>>'))
m = int(input('题目数量(输入0则无限)>>>'))
t1,t2,count = time(),0,0
if fuhao == '1':
    if m == 0:
        while True:
            a,b = randint(10**(n-1),10**n-1),randint(10**(n-1),10**n-1)
            try:
                ans = int(input('%d+%d=' %(a,b)))
                if a+b == ans:
                    count += 1
                    t2 = time()-t1
                else:
                    print('错误,正确答案是',a+b)
                    break
            except:
                print('输入错误,跳过')
    else:
        for i in range(m):
            a,b = randint(10**(n-1),10**n-1),randint(10**(n-1),10**n-1)
            try:
                ans = int(input('%d+%d=' %(a,b)))
                if a+b == ans:
                    count += 1
                else:
                    print('错误,正确答案是',a+b)
            except:
                print('输入错误,跳过')
        t2 = time()-t1
elif fuhao == '2':
    if m == 0:
        while True:
            try:
                a,b = randint(10**(n-1),10**n-1),randint(10**(n-1),10**n-1)
                ans = int(input('%d*%d=' %(a,b)))
                if a*b == ans:
                    count += 1
                    t2 = time()-t1
                else:
                    print('错误,正确答案是',a*b)
                    break
            except:
                print('输入错误,跳过')
    else:
        for i in range(m):
            try:
                a,b = randint(10**(n-1),10**n-1),randint(10**(n-1),10**n-1)
                ans = int(input('%d*%d=' %(a,b)))
                if a*b == ans:
                    count += 1
                else:
                    print('错误,正确答案是',a*b)
            except:
                print('输入错误,跳过')
        t2 = time()-t1
elif fuhao == '3':
    if m == 0:
        while True:
            a,b,c,d = randint(1,99),randint(-99,99),randint(1,99),randint(-99,99)
            e,f = b,d
            if b >= 1:
                b = '+' + str(b) + 'i'
            elif b <= -1:
                b = str(b) + 'i'
            else:
                b = ''
            if d >= 1:
                d = '+' + str(d) + 'i'
            elif d <= -1:
                d = str(d) + 'i'
            else:
                d = ''
            ans = str(input('(%d%s)(%d%s)=' %(a,b,c,d)))
            if a*f+c*e > 0:
                t = '+' + str(a*f+c*e) + 'i'
            elif a*f+c*e == 0:
                t = ''
            else:
                t = str(a*f+c*e) + 'i'
            if str(a*c-e*f) + t == ans:
                count += 1
                t2 = time()-t1
            else:
                print('错误,正确答案是',str(a*c-e*f) + t)
                break
    else:
        for i in range(m):
            a,b,c,d = randint(1,99),randint(-99,99),randint(1,99),randint(-99,99)
            e,f = b,d
            if b >= 1:
                b = '+' + str(b) + 'i'
            elif b <= -1:
                b = str(b) + 'i'
            else:
                b = ''
            if d >= 1:
                d = '+' + str(d) + 'i'
            elif d <= -1:
                d = str(d) + 'i'
            else:
                d = ''
            ans = str(input('(%d%s)(%d%s)=' %(a,b,c,d)))
            if a*f+c*e > 0:
                t = '+' + str(a*f+c*e) + 'i'
            elif a*f+c*e == 0:
                t = ''
            else:
                t = str(a*f+c*e) + 'i'
                
            if str(a*c-e*f) + t == ans:
                count += 1
            else:
                print('错误,正确答案是',str(a*c-e*f) +t)
        t2 = time()-t1
print('你答对了%d道题,用时%.2f秒' % (count,t2))