# 设计一个程序,用来实现帮助小学生进行算术运算练习,它具有以下功能:
# 提供基本算术运算(加减乘)的题目,每道题中的操作数是随机产生的,
# 练习者根据显示的题目输入自己的答案,程序自动判断输入的答案是否正确并显示出相应的信息。最后显示正确率。
# 思路:
# 运行程序, 输入测试数字的大小范围
# 输入测试题目数量
# 任意键进入测试
# 系统进行测试并判断对错
# 系统根据得分情况进行总结,退出程序

 

import random
import time

while True:
    i = 0
    j = 0
    print("""
            ☆☆☆☆☆基本算术运算系统☆☆☆☆☆
        1-  ☆☆☆☆☆☆——整数加法——☆☆☆☆☆☆
        2-  ☆☆☆☆☆☆——整数减法——☆☆☆☆☆☆
        3-  ☆☆☆☆☆☆——整数乘法——☆☆☆☆☆☆
        4-  ☆☆☆☆☆☆——整数除法——☆☆☆☆☆☆
        5-  ★★★★★★★——退出——★★★★★★★
           """)
    chose = int(input('请选择要练习的题型:'))
    if chose == 1:
        m = int(input("请输入测试范围的下限:"))
        n = int(input("请输入测试范围的上限:"))
        print("提示:测试范围:(%d,%d),题型为:加法" % (m, n))
        num = int(input("请输入测试题目数量:"))
        while num > 0:
            num -= 1
            num1 = random.randint(m, n)
            num2 = random.randint(m, n)
            print('%d+%d=' % (num1, num2))
            he = num1 + num2
            zj = int(input("请输入你的答案:"))
            if he == zj:
                i += 1
                if num != 0:
                    print('计算正确,请看下一题:')
                    time.sleep(1)
                else:
                    print('答题结束!')
                    time.sleep(1)
                    break
            else:
                j += 1
                if num != 0:
                    print('计算错误,请看下一题:')
                    time.sleep(1)
                else:
                    print('答题结束!')
                    time.sleep(1)
                    break
        if num == 0:
            print('做正确%d道题,做错误%d道题' % (i, j))
            print('正确率:{:.0%}'.format(i / (i + j)))
        verify = int(input("继续做题请按1,结束请按0"))
        if verify == 1:
            print("你选择继续做题")
            time.sleep(1)
        elif verify == 0:
            print("你选择结束做题")
            time.sleep(1)
            break

    elif chose == 2:
        m = int(input("请输入测试范围的下限:"))
        n = int(input("请输入测试范围的上限:"))
        print("提示:测试范围:(%d,%d),题型为:减法" % (m, n))
        num = int(input("请输入测试题目数量:"))
        while num > 0:
            num -= 1
            num1 = random.randint(m, n)
            num2 = random.randint(m, n)
            print('%d-%d=' % (num1, num2))
            jian = num1 - num2
            zj = int(input("请输入你的答案:"))
            if jian == zj:
                i += 1
                if num != 0:
                    print('计算正确,请看下一题:')
                    time.sleep(1)
                else:
                    print('答题结束!')
                    time.sleep(1)
                    break
            else:
                j += 1
                if num != 0:
                    print('计算错误,请看下一题:')
                    time.sleep(1)
                else:
                    print('答题结束!')
                    time.sleep(1)
                    break
        if num == 0:
            print('做正确%d道题,做错误%d道题' % (i, j))
            print('正确率:{:.0%}'.format(i / (i + j)))
        verify = int(input("继续做题请按1,结束请按0"))
        if verify == 1:
            print("你选择继续做题")
            time.sleep(1)
        elif verify == 0:
            print("你选择结束做题")
            time.sleep(1)
            break

    elif chose == 3:
        m = int(input("请输入测试范围的下限:"))
        n = int(input("请输入测试范围的上限:"))
        print("提示:测试范围:(%d,%d),题型为:乘法" % (m, n))
        num = int(input("请输入测试题目数量:"))
        while num > 0:
            num -= 1
            num1 = random.randint(m, n)
            num2 = random.randint(m, n)
            print('%d*%d=' % (num1, num2))
            cheng = num1 * num2
            zj = int(input("请输入你的答案:"))
            if cheng == zj:
                i += 1
                if num != 0:
                    print('计算正确,请看下一题:')
                    time.sleep(1)
                else:
                    print('答题结束!')
                    time.sleep(1)
                    break
            else:
                j += 1
                if num != 0:
                    print('计算错误,请看下一题:')
                    time.sleep(1)
                else:
                    print('答题结束!')
                    time.sleep(1)
                    break
        if num == 0:
            print('做正确%d道题,做错误%d道题' % (i, j))
            print('正确率:{:.0%}'.format(i / (i + j)))
        verify = int(input("继续做题请按1,结束请按0"))
        if verify == 1:
            print("你选择继续做题")
            time.sleep(1)
        elif verify == 0:
            print("你选择结束做题")
            time.sleep(1)
            break

    elif chose == 4:
        m = int(input("请输入测试范围的下限:"))
        n = int(input("请输入测试范围的上限:"))
        print("提示:测试范围:(%d,%d),题型为:除法" % (m, n))
        if m == 0 or n == 0:
            print("请重新输入不为0的上下限")
            m = int(input("请输入测试范围的下限:"))
            n = int(input("请输入测试范围的上限:"))
            print("修改后的上下限:(%d,%d)" % (m, n))
            print("提示:0/任何不为0的数其结果为0")
        num = int(input("请输入测试题目数量:"))
        while num > 0:
            num -= 1
            num1 = random.randint(m, n)
            num2 = random.randint(m, n)
            print('%d/%d=' % (num1, num2))
            he = num1 / num2
            chu = round(he, 2)
            zj = float(input("请输入你的答案:"))
            if chu == zj:
                i += 1
                if num != 0:
                    print('计算正确,请看下一题:')
                    time.sleep(1)
                else:
                    print('答题结束!')
                    time.sleep(1)
                    break
            else:
                j += 1
                if num != 0:
                    print('计算错误,请看下一题:')
                    time.sleep(1)
                else:
                    print('答题结束!')
                    time.sleep(1)
                    break
        if num == 0:
            print('做正确%d道题,做错误%d道题' % (i, j))
            print('正确率:{:.0%}'.format(i / (i + j)))
        verify = int(input("继续做题请按1,结束请按0"))
        if verify == 1:
            print("你选择继续做题")
            time.sleep(1)
        elif verify == 0:
            print("你选择结束做题")
            time.sleep(1)
            break

    elif chose == 5:
        print('练习到此结束!')
        time.sleep(1)
        break
    else:
        print('系统无法识别您的指令,稍后请重新输入!')
        time.sleep(1)