- 凯撒密码编码与解码
- 代码:
def code(i):
res = ""
for a in i:
res = res + chr(ord(a) + 3)
return res
def decode(i):
res = ""
for a in i:
res = res + chr(ord(a) - 3)
return res
f1 = open("CLM.txt","r",encoding='utf-8')
CLM = f1.read()
CLM22=code(CLM)
print("加密后:"+CLM22)
f2 = open("CLM1.txt","w",encoding='utf-8')
f2.write(CLM22)
f1.close()
f2.close()
f2 = open("key11","r",encoding='utf-8')
CLM1 = f2.read()
f2.close()
CLM11=decode(CLM1)
print("加密前:"+CLM11)
运行结果:
字符串操作:
- 解析身份证号:生日、性别、地区编号等。
- 代码:
ID = input('请输入身份证号码: ')
if len(ID) == 18:
print("身份证号码是:" + ID)
else:
print("错误的身份证号码")
ID_add = ID[0:6]
ID_days = ID[6:14]
ID_sex = ID[16]
ID_check = ID[17]
ID_day = ID_days[6:8]
ID_moon = ID_days[4:6]
ID_years = ID_days[0:4]
if int(ID_sex)%2 == 0:
gender = "女士"
else:
gender = "男士"
print(gender+"您生日为: "+ID_years+'年'+ID_moon+'月'+ID_day+'日'+"你的出生地区编号为:"+ID_add)
运行结果:
- 英文词频统计预处理
- 下载一首英文的歌词或文章或小说。
- 将所有大写转换为小写
- 将所有其他做分隔符(,.?!)替换为空格
- 分隔出一个一个的单词
- 并统计单词出现的次数。
file = open("CLM","r",encoding='utf-8')
text = file.read()
file.close()
text.replace(",", "")
text.replace(".", "")
text.replace(" ", "")
text.lower()
text=text.split()
number = {}
for i in text:
if i not in number:
number[i] = 1
else:
number[i] += 1
print(number)
运行结果:
- 网址观察与批量生成
- 代码:
for i in range(6, 28):
print("https://www.cnblogs.com/qiannuohan/p/{}.html".format(i))
运行结果: