• 口算题卡升级版本


    import random

    count = 0
    strA = ""
    strB = ""

    while True:
        # 随机生成1或者2,表示是+还是-
        addOrreduce = random.randint(1, 2)
        # 随机生成两个数字
        a = random.randint(10, 200)
        b = random.randint(10, 200)
        if addOrreduce == 1:
            if a + b > 100:
                continue
            strA = strA + " " + str(a) + "+" + str(b) + "="
            strB = strB + " " + str(a) + "+" + str(b) + "=" + str(a + b)

        else:
            if a - b < 0:
                continue
            strA = strA + " " + str(a) + "-" + str(b) + "="
            strB = strB + " " + str(a) + "-" + str(b) + "=" + str(a - b)

        count = count + 1
        if count == 1000:
            break

    # 写文件
    with open('c:/学生用卷.txt', 'w',encoding='utf-8') as f:
        f.write(strA)

    with open('c:/家长用卷.txt', 'w',encoding='utf-8') as f:
        f.write(strB)

  • 相关阅读:
    Java线程
    IO流
    staitc
    权限修饰符
    nexus
    Maven
    Git 常用命令
    获取url参数
    创建存储过程和函数
    三层引号
  • 原文地址:https://www.cnblogs.com/littlehb/p/11297749.html
Copyright © 2020-2023  润新知