菜鸟学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 ...
随机推荐
- GitHub的Repository权限将public转为private
2019年1月7日,GitHub CEO Nat Friedman 于官方博客公开发文,称“New year, new GitHub”,宣布从此将免费无限地为普通用户提供私有仓库服务. 因此,我们可以 ...
- python接口自动化(十)--post请求四种传送正文方式(详解)
简介 post请求我在python接口自动化(八)--发送post请求的接口(详解)已经讲过一部分了,主要是发送一些较长的数据,还有就是数据比较安全等.我们要知道post请求四种传送正文方式首先需要先 ...
- 我眼中的 Nginx(二):HTTP/2 dynamic table size update
张超:又拍云系统开发高级工程师,负责又拍云 CDN 平台相关组件的更新及维护.Github ID: tokers,活跃于 OpenResty 社区和 Nginx 邮件列表等开源社区,专注于服务端技术的 ...
- Elasticsearch之索引模板index template与索引别名index alias
为什么需要索引模板? 在实际工作中针对一批大量数据存储的时候需要使用多个索引库,如果手工指定每个索引库的配置信息(settings和mappings)的话就很麻烦了. 所以,这个时候,就存在创建索引模 ...
- ZooKeeper 03 - ZooKeeper集群的脑裂问题 (Split Brain问题)
目录 1 ZooKeeper的主从机制 2 什么是ZooKeeper的脑裂 2.1 脑裂现象的表现 2.2 为什么会出现脑裂 3 ZooKeeper如何解决"脑裂" 3.1 3种可 ...
- RabbitMQ在Windows环境下的安装与使用
Windows下安装RabbitMQ 环境配置 部署环境 部署环境:windows server 2008 r2 enterprise 官方安装部署文档:http://www.rabbitmq.com ...
- zk分布式任务管理
在我们的系统开发过程 中不可避免的会使用到定时任务的功能,而当我们在生产环境部署的服务超过1台时,就需要考虑任务调度的问题,防止两台或多台服务器上执行同一个任务,这个问题今天咱们就用zookeeper ...
- Asp.Net Core 轻松学-利用日志监视进行服务遥测
前言 在 Net Core 2.2 中,官方文档表示,对 EventListener 这个日志监视类的内容进行了扩充,同时赋予了跟踪 CoreCLR 事件的权限:通过跟踪 CoreCLR 事件 ...
- 并发系列(6)之 ThreadPoolExecutor 详解
本文将主要介绍我们平时最常用的线程池 ThreadPoolExecutor ,有可能你平时没有直接使用这个类,而是使用 Executors 的工厂方法创建线程池,虽然这样很简单,但是很可能因为这个线程 ...
- SLAM+语音机器人DIY系列:(二)ROS入门——8.理解roslaunch在大型项目中的作用
摘要 ROS机器人操作系统在机器人应用领域很流行,依托代码开源和模块间协作等特性,给机器人开发者带来了很大的方便.我们的机器人“miiboo”中的大部分程序也采用ROS进行开发,所以本文就重点对ROS ...