赞
踩
1.编写程序生成九九乘法表,并将之写入到文本文件exercise7_1.txt中。程序保存为exercise7_1.py。
- f = open(r'd:\exercise7_1.txt', 'a+')
- with open('d:\\exercise7_1.txt','a+') as f:
- for j in range(1,10):
- for i in range(1,j+1):
- f.write(str(i)+'*'+str(j)+ '=' + str(i*j) + '\t')
- f.write('\n')
- f.close()
2.编写程序,提示用户输入字符串。将所输入的字符串,以及对应字符串的长度写入exercise7_2.txt中。程序保存为exercise7_2.py。
- f = open(r'd:\exercise7_2.txt', 'a+')
- with open('d:\\exercise7_2.txt','a+') as f:
- s=input("请输入一个字符串:")
- f.write("输入的字符串是:" + str(s) +"\n"+ "字符串的长度是:" + str(len(s)))
- f.close()
3.创建一个exercise7_3.xlsx文件,在C5单元格写入字符串“我喜欢编程”。程序保存为exercise7_3.py。
- import openpyxl
- workbook=openpyxl.Workbook()
- sheet1=workbook.active
- sheet1.cell(row=5,column=3).value="我喜欢编程"
- workbook.save("d:\\exercise7_3.xlsx")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。