首页 / PYTHON / 菜鸟学python之程序初体验
菜鸟学python之程序初体验
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了菜鸟学python之程序初体验,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2460字,纯文字阅读大概需要4分钟。
内容图文
![菜鸟学python之程序初体验](/upload/InfoBanner/zyjiaocheng/838/202ee2b0b4754381a07d1894c28f1f8d.jpg)
作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2684
1.字符串操作:
- 解析身份证号:生日、性别、出生地等。
- 凯撒密码编码与解码
- 网址观察与批量生成
def idption(): str_id= input("请输入身份证号:") if(len(str_id)!=18): print("你输入的身份证号有误,请重新输入") idption() else: print("你出生省份为:"+str_id[0:2]) print("你出生市区为:" + str_id[2:4]) print("你出生县区为:" + str_id[4:6]) print("你出生日期为:" + str_id[6:14]) print("你出生户口派出所为:" + str_id[14:16]) if(str_id[16:17]=='1'): print("你为男性且编码:" + str_id[16:17]) else: print("你为女性且编码:" + str_id[16:17]) print("校验码为:" + str_id[17:18]+"\n")
运行结果:
2.英文词频统计预处理
- 下载一首英文的歌词或文章或小说。
- 将所有大写转换为小写
- 将所有其他做分隔符(,.?!)替换为空格
- 分隔出一个一个的单词
- 并统计单词出现的次数。
def danciption(): text='''I'm a Big big girl in a Big big world It's not a Big big thing if you leave me but I do do feel that I too too will miss you much miss you much... I can see the first leaf falling it's all yellow and nice It's so very cold outside like the way I'm feeling inside I'm a Big big girl in a Big big world It's not a big big thing if you leave me but I do do feel that I too too will miss you much miss you much... Outside it's now raining and tears are falling from my eyes why did it have to happen why did it all have to end I'm a big big girl in a big big world It's not a big big thing if you leave me but I do do feel that I too too will miss you much miss you much... I have your arms around me ooooh like fire but when I open my eyes you're gone... I'm a big big girl in a big big world It's not a big big thing if you leave me but I do do feel that I too too will miss you much miss you much... I'm a big big girl in a big big world It's not a big big thing if you leave me but I do feel I will miss you much miss you much...''' s=',.!?:' for c in s: text=text.replace(c,'') print(text.split()) print("单词词频次数:") print("big:",text.count('big')) print("Big:",text.count('Big')) print("a:",text.count('a'))
截图如下:
3.文件操作
- 同一目录、绝对路径、相对路径
- 凯撒密码:从文件读入密函,进行加密或解密,保存到文件。
- 词频统计:下载一首英文的歌词或文章或小说,保存为utf8文件。从文件读入文本进行处理。
#同一路径
f= open(r"Plaintext", 'r', encoding='utf8')
#相对路径
f2=open(r"..\Lin\file_text\Plaintext", 'r', encoding='utf8')
#绝对路径
f3=open(r"G:\PycharmProjects\Lin\file_text\Plaintext", 'r', encoding='utf8')
text=f.read()
f.close()
t=text.find(',')
print(text[0:t])
print(text[t+1:len(text)])
截图
4.函数定义
- 加密函数
- 解密函数
- 读文本函数
内容总结
以上是互联网集市为您收集整理的菜鸟学python之程序初体验全部内容,希望文章能够帮你解决菜鸟学python之程序初体验所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。