生成计算题
Posted grub007
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生成计算题相关的知识,希望对你有一定的参考价值。
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()
以上是关于生成计算题的主要内容,如果未能解决你的问题,请参考以下文章