1.统计小写字母出现的次数
str=input("please enter a text:")
str=str.lower()
lst=[chr(i) for i in range(97,123)]
print(lst)
res={}
for i in str:
if i in lst:
res[i]=res.get(i,0)+1
res2=list(res.items())
res2.sort(key=lambda x:x[1],reverse=True)
print(res2)
for i in range(len(res2)):
word,count=res2[i]
print("{:5}{:5}".format(word,count))
2.统计出现的数据的次数
str=input("please enter a text:")
a={}
for i in str:
a[i]=a.get(i,0)+1
b=list(a.items())
b.sort(key=lambda x:x[1],reverse=True)
for i in range(len(b)):
word,count=b[i]
print("{:5}{:5}".format(word,count))
3.
str=input("please enter a text:")
res={}
for i in str:
res[i]=res.get(i,0)+1
print(res)
res2=list(res.items())
res2.sort(key=lambda x:x[1],reverse=True)
print(res2)
for i in range(len(res2)):
word,count=res2[i]
print("{:5}{:5}".format(word,count))
4.随机生成验证码
import random
lst1=[chr(i) for i in range(97,123)]
lst2=[chr(i) for i in range(65,91)]
lst3=[i for i in range(0,10)]
res=lst1+lst2+lst3
for i in range(10):
for i in range(8):
print(random.choice(res),end='')
print()
//反复用到了构造列表
运用文件的相关知识,矩阵,excel
import random
word=''
for row in range(10):
for line in range(10):
word+=str(random.randint(1,100))+' '
word+='\n'
print(word)
f=open('2.txt','w')
f.write(word)
f.close()
x=open('1.csv','w')
y=open('2.txt','r')
for i in y:
s=i.replace(' ',',')
x.write(s)
x.close()
y.close()