作业来源: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之程序初体验的更多相关文章

  1. wxWidgets刚開始学习的人导引(3)——wxWidgets应用程序初体验

    wxWidgets刚開始学习的人导引全文件夹   PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wx ...

  2. 微信小程序初体验,入门练手项目--通讯录,部署上线(二)

    接上一篇<微信小程序初体验,入门练手项目--通讯录,后台是阿里云服务器>:https://www.cnblogs.com/chengxs/p/9898670.html 开发微信小程序最尴尬 ...

  3. wxWidgets初学者导引(3)——wxWidgets应用程序初体验

    wxWidgets初学者导引全目录   PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wxSmith ...

  4. python窗体——pyqt初体验

    连续两周留作业要写ftp的作业,从第一周就想实现一个窗体版本的,但是时间实在太短,qt零基础选手表示压力很大,幸好又延长了一周时间,所以也就有了今天这篇文章...只是为了介绍一些速成的方法,还有初学者 ...

  5. 【尝新】微信小程序初体验

    文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/?t=1474644089434 根据文档地址中下载微信开发工具后,按照文档指引可以创建一个快速体验的小d ...

  6. 菜鸟学IT之python词云初体验

    作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2822 1. 下载一长篇中文小说. 2. 从文件读取待分析文本. txt = ...

  7. 菜鸟学python之大数据的初认识

    这次作业的要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2639 1.这些分析所采用数据来源是什么? 国家数据库:中国铁路 ...

  8. Python操作RabbitMQ初体验(一)

    由于想用Python实现一套分布式系统,来管理和监控CDN的内容与运行状态,误打误撞认识了RabbitMQ,推荐的人很多,如余锋<我为什么要选择RabbitMQ>等等. 在MQ这个词汇映入 ...

  9. 微信小程序初体验,入门练手项目--通讯录,后台是阿里云服务器(一)

    内容: 一.前言 二.相关概念 三.开始工作 四.启动项目起来 五.项目结构 六.设计理念 七.路由 八.部署线上后端服务 同步交流学习社区: https://www.mwcxs.top/page/4 ...

随机推荐

  1. Python 闭包小记

    闭包就是能够读取其他函数内部变量的函数.例如在javascript中,只有函数内部的子函数才能读取局部变量,所以闭包可以理解成“定义在一个函数内部的函数“.在本质上,闭包是将函数内部和函数外部连接起来 ...

  2. MySQL配置参数说明

    MYSQL服务器my.cnf配置参数详解: 硬件:内存16G [client] port = 3306 socket = /data/mysql.sock [mysql] no-auto-rehash ...

  3. 中缀表达式得到后缀表达式(c++、python实现)

    将中缀表达式转换为后缀表达式的算法思想如下: 从左往右开始扫描中缀表达式 遇到数字加入到后缀表达式 遇到运算符时: 1.若为‘(’,入栈 2.若为’)‘,把栈中的运算符依次加入后缀表达式,直到出现'( ...

  4. .NET Core开发者的福音之玩转Redis的又一傻瓜式神器推荐

    作者:依乐祝 原本链接:https://www.cnblogs.com/yilezhu/p/9947905.html 引子 为什么写这篇文章呢?因为.NET Core的生态越来越好了!之前玩转.net ...

  5. ByteView和Sink

    久违啦米娜桑!!! 最近有点忙,一月有余没有更新了,实在对不起大家!!! 上线后看到不少朋友发的私信,感谢大家的赞许与信任,后面我会尽最大的努力按时更新,不断推出更优质的文章!!! 本来计划最后花1讲 ...

  6. Linux之用户和权限

    自从我大微软终于放下身段,决定给开源社区一个迟来的拥抱,追随多年的拥趸们像是突然得到了女神的垂青,各种茫然失措.痛哭流涕.欢欣鼓舞,纷纷唱了起来:“等了好久终于等到今天,梦了好久终于把梦实现……”唱完 ...

  7. 基于IdentityServer的系统对接微信公众号

    业务需求 公司有两个业务系统,A和B,AB用户之间属于多对一的关系,数据库里面也就是两张表,A表有个外键指向B.现在需要实现以下几个功能. A用户扫描B的二维码,填写相关的注册信息,注册完成之后自动属 ...

  8. Writing a Simple Publisher and Subscriber

    用c++实现一个publisher/subscriber publisher #include "ros/ros.h" #include "std_msgs/String ...

  9. Vcomputer简介

    1.Vcompter存储程序式计算机虚拟机软件简介   Vcompter存储程序式计算机虚拟机软件的文件名为comp_alpha(一般要先安装java运行环境,然后双击该软件即可运行),该软件是桂林电 ...

  10. 杭电ACM2019--数列有序!

    数列有序! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...