1、使用Python完成九九乘法表:
for i in range(1,10): for j in range(1,i+1): print(" %sx%s=%s"%(j,i,i*j),end=‘‘) print(" ")
2、将xwls模块写入到Python编写环境中:
pip install xlwt
3、要写入到excle中,我们只需要给九九乘法表穿上外套就可以了:
import xlwt wbk = xlwt.Workbook() sheet = wbk.add_sheet("jiujiu") for i in range (1,10): for j in range(1,i+1): sheet.write(i-1,j-1,"%sx%s=%s"%(j,i,j*i)) wbk.save("D:/python/log.test.xls")