菜鸟学python之程序初体验
作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2684
1.字符串操作:
- 解析身份证号:生日、性别、出生地等。
def idption():
str_id= input("请输入身份证号:")
if(len(str_id)!=):
print("你输入的身份证号有误,请重新输入")
idption()
else:
print("你出生省份为:"+str_id[:])
print("你出生市区为:" + str_id[:])
print("你出生县区为:" + str_id[:])
print("你出生日期为:" + str_id[:])
print("你出生户口派出所为:" + str_id[:])
if(str_id[:]==''):
print("你为男性且编码:" + str_id[:])
else:
print("你为女性且编码:" + str_id[:])
print("校验码为:" + str_id[:]+"\n")
运行结果:

- 凯撒密码编码与解码
def encryption():
print("导入文件中……")
fo = open(r"..\Lin\file_text\Plaintext", "r", encoding="utf-8")
str1 = fo.read()
print("明文为:",str1)
fo.close()
str_raw = str1
k = int(input("请输入位移值:"))
str_change = str_raw.lower()
str_list = list(str_change)
str_list_encry = str_list
i =
while i < len(str_list):
if ord(str_list[i]) < - k:
str_list_encry[i] = chr(ord(str_list[i]) + k)
else:
str_list_encry[i] = chr(ord(str_list[i]) + k - )
i = i +
print("加密结果为:" + "".join(str_list_encry))
print("保存密文……")
te="".join(str_list_encry)
fo = open(r"..\Lin\file_text\Ciphertext", "w")
fo.write(te)
def decryption():
fo = open(r"..\Lin\file_text\Ciphertext", "r", encoding="utf-8")
str1 = fo.read()
print("密文:", str1)
fo.close()
str_raw = str1
k = int(input("请输入位移值:"))
str_change = str_raw.lower()
str_list = list(str_change)
str_list_decry = str_list
i =
while i < len(str_list):
if ord(str_list[i]) >= + k:
str_list_decry[i] = chr(ord(str_list[i]) - k)
else:
str_list_decry[i] = chr(ord(str_list[i]) + - k)
i = i +
print("解密结果为:" + "".join(str_list_decry))
截图:

- 网址观察与批量生成
def webption():
for i in range(,):
url='http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i)
print(url)
截图:

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.函数定义
- 加密函数
str_raw = input("请输入明文:")
k = int(input("请输入位移值:"))
str_change = str_raw.lower()
str_list = list(str_change)
str_list_encry = str_list
i =
while i < len(str_list):
if ord(str_list[i]) < -k:
str_list_encry[i] = chr(ord(str_list[i]) + k)
else:
str_list_encry[i] = chr(ord(str_list[i]) + k - )
i = i+
print ("加密结果为:"+"".join(str_list_encry))
- 解密函数
str_change = str_raw.lower()
str_list = list(str_change)
str_list_decry = str_list
i = 0
while i < len(str_list):
if ord(str_list[i]) >= 97+k:
str_list_decry[i] = chr(ord(str_list[i]) - k)
else:
str_list_decry[i] = chr(ord(str_list[i]) + 26 - k)
i = i+1
print ("解密结果为:"+"".join(str_list_decry))
- 读文本函数
f= open(r"..\Lin\file_text\Plaintext", 'r', encoding='utf8')
text=f.read()
f.close()
t=text.find(',')
print(text[:t])
print(text[t+:len(text)])
菜鸟学python之程序初体验的更多相关文章
- wxWidgets刚開始学习的人导引(3)——wxWidgets应用程序初体验
wxWidgets刚開始学习的人导引全文件夹 PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wx ...
- 微信小程序初体验,入门练手项目--通讯录,部署上线(二)
接上一篇<微信小程序初体验,入门练手项目--通讯录,后台是阿里云服务器>:https://www.cnblogs.com/chengxs/p/9898670.html 开发微信小程序最尴尬 ...
- wxWidgets初学者导引(3)——wxWidgets应用程序初体验
wxWidgets初学者导引全目录 PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wxSmith ...
- python窗体——pyqt初体验
连续两周留作业要写ftp的作业,从第一周就想实现一个窗体版本的,但是时间实在太短,qt零基础选手表示压力很大,幸好又延长了一周时间,所以也就有了今天这篇文章...只是为了介绍一些速成的方法,还有初学者 ...
- 【尝新】微信小程序初体验
文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/?t=1474644089434 根据文档地址中下载微信开发工具后,按照文档指引可以创建一个快速体验的小d ...
- 菜鸟学IT之python词云初体验
作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2822 1. 下载一长篇中文小说. 2. 从文件读取待分析文本. txt = ...
- 菜鸟学python之大数据的初认识
这次作业的要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2639 1.这些分析所采用数据来源是什么? 国家数据库:中国铁路 ...
- Python操作RabbitMQ初体验(一)
由于想用Python实现一套分布式系统,来管理和监控CDN的内容与运行状态,误打误撞认识了RabbitMQ,推荐的人很多,如余锋<我为什么要选择RabbitMQ>等等. 在MQ这个词汇映入 ...
- 微信小程序初体验,入门练手项目--通讯录,后台是阿里云服务器(一)
内容: 一.前言 二.相关概念 三.开始工作 四.启动项目起来 五.项目结构 六.设计理念 七.路由 八.部署线上后端服务 同步交流学习社区: https://www.mwcxs.top/page/4 ...
随机推荐
- Socket模拟HTTP请求
WEB服务器可以可以理解为socket的上层封装,其也是TCP/IP协议,只要知道其IP地址和端口号就可以与他进行通信了 与WEB服务器数据交互,其重点在于请求头,如果请求头不对则不能进行数据传输 简 ...
- 测试 ASP.NET Core API Controller
本文需要您了解ASP.NET Core MVC/Web API, xUnit以及Moq相关知识. 这里有xUnit和Moq的介绍: https://www.cnblogs.com/cgzl/p/917 ...
- was cached in the local repository, resolution will not be reattempted until the update interval of fintech has elapsed or updates are forced
今天使用命令mvn compile编译maven项目时提示错误信息,错误信息如下: [ERROR] Failed to execute goal on project <project_name ...
- [小技巧]C#中如何为枚举类型添加描述方法
背景 在我们的日常开发中,我们会经常使用枚举类型.有时我们只需要显示枚举的值或者枚举值对应名称, 但是在某些场景下,我们可能需要将枚举值显示为不同的字符串. 例: 当前我们有如下枚举Level pub ...
- 知识小罐头06(tomcat8请求源码分析 中)
更正上一篇一个小错误,Connector中首先是将socket请求过来的信息封装成一个普通的Request对象(上一篇我写成HttpRequest对象,失误失误,根本就木有HttpRequest这样的 ...
- Python3+unitest自动化测试初探(上篇)
目录 1.概念介绍 2.准备工作 3.一个简单的例子 4.test fixture 5.测试套 1.概念介绍 unit test:单元测试,可以简单粗暴地理解成用一段代码去测试另外一段代码.unitt ...
- Linux环境变量配置全攻略
Linux环境变量配置 在自定义安装软件的时候,经常需要配置环境变量,下面列举出各种对环境变量的配置方法. 下面所有例子的环境说明如下: 系统:Ubuntu 14.0 用户名:uusama 需要配置M ...
- 使用 FFT 分析周期性数据
可以使用傅里叶变换来分析数据中的变化,例如一个时间段内的自然事件. 天文学家使用苏黎世太阳黑子相对数将几乎 300 年的太阳黑子的数量和大小制成表格.对大约 1700 至 2000 年间的苏黎世数绘图 ...
- 【转载】java 中 String s = new String("abc") 创建了几个对象?!
原文链接点这里,感谢博主分享 答案是两个,现在我们具体的说一下: String s = new String("abc"); 首先我们要明白两个概念,引用变量和对象,对象一般通过n ...
- Arrays工具、二维数组以及LeetCode练习题
1 Arrays PS:Arrays位于java.util包下 int binarySearch(type[] a, type key); 使用二分法查询 key 元素在 a 数组中的索引,如果数组不 ...