계산 문제 생 성

import random, os
import xlsxwriter

def create_dgit(num):
    count = 0
    foo = [lambda x, y: x+y, lambda x, y: x-y]
    while True:
        if count == num:
            break
        a, b, c = random.randint(1, 20), random.randint(1, 20), random.randint(0, 1)
        if foo[c](a, b) <= 20 and foo[c](a, b) > 0:
            yield "{} + {} =".format(a, b) if c == 0 else "{} - {} =".format(a, b)
            count += 1

if __name__ == "__main__":
    row, col = 0, 0
    workbook = xlsxwriter.Workbook('exercises.xlsx')
    worksheet = workbook.add_worksheet()

    for i in create_dgit(1000):
        if col > 4:
            row += 1
            col = 0
        worksheet.write(row, col, i)
        col += 1
    workbook.close()

 
다음으로 전송:https://www.cnblogs.com/grub007/p/9800151.html

좋은 웹페이지 즐겨찾기