- 编程题1
f=open('file1.txt','w')
f.write('My name is Lin')
f.write('I am from China')
f.close()
k=open('file1.txt','r')
j=k.read()
p=input('请输入一个需要查找的字符:')
num=0
for i in j:
if p==i:
num+=1
print(num)
- 编程题2
f=open('file1.txt','w')
f.write('My name is Lin')
f.write('I am from China')
f.close()
with open('file1.txt','r') as fp:
line=fp.readlines()
newLine=[i.swapcase() for i in line]
with open('file1.txt','w') as fp:
fp.writelines(newLine)
- 编程题3
import numpy as np
data=np.random.randn(10,10)
np.savetxt('Matrix.csv',data,delimiter=',')
- 编程题4
转载
https://blog.csdn.net/zhi_it_coder/article/details/80740078blog.csdn.net- 编程题5(我用 pandas 好像有点粗暴)
import pandas as pd
lie=[]
q=1
while q==1:
p=input('请输入列表需要包含的元素:')
lie.append(p)
q=eval(input('继续,输入(0或1):'))
data=pd.DataFrame(lie)
data.to_csv('list.csv',encoding='gbk')