码迷,mamicode.com
首页 > 其他好文 > 详细

字符串操作练习:星座、凯撒密码、99乘法表、词频统计预处理

时间:2017-09-20 19:42:41      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:blog   arm   turn   and   歌词   where   技术   red   控制   

 

 

 

恺撒密码的编码

技术分享

技术分享

{ }里的格式控制 <序号>:<填充><对齐><宽度><千分位><精度><类型>

技术分享

技术分享

 技术分享

中华人民共和国国内生产总值(GDP)
689,136.89亿元(2015年)

a=float(input("please input money:"))
b=input("please input year:")
print("中华人民共和国国内生产总值(GDP){0:,.2f}亿元({1}年)".format(a,b))

实例:打出99乘法表

for i in range(1,10):
    for j in range(1,i+1):
        print(j,"*",i,"=",i*j," ",end=‘‘)
    print(end=‘\n‘)
技术分享

实例: 下载一首英文的歌词或文章,统计单词出现的次数,将所有,.?!替换为空格,将所有大写转换为小写。

sr=‘‘‘Just one last dance ,oh baby just one last dance!
We meet in the night in the Spanish café,
I look in your eyes just don‘t know what to say,
It feels like I‘m drowning in salty water,A few hours left ‘til the sun‘s gonna rise,
tomorrow will come an it‘s time to realize.our love has finished forever,
how I wish to come with you!how I wish we make it through!
Just one last dance!before we say goodbye,
when we sway and turn round and round and round,
it‘s like the first time,Just one more chance,
hold me tight and keep me warm.cause the night is getting cold.
and I don‘t know where I belong,Just one last dance! ‘‘‘
技术分享

 

print("dance出现次数:",sr.count(‘dance‘))
for i in sr:
    sr=sr.replace(‘,‘,‘ ‘)
    sr=sr.replace(‘!‘,‘ ‘)
    sr=sr.replace(‘?‘,‘ ‘)
print(sr)
for i in sr:
    sr=sr.lower()
print(sr)
技术分享
技术分享

 

字符串操作练习:星座、凯撒密码、99乘法表、词频统计预处理

标签:blog   arm   turn   and   歌词   where   技术   red   控制   

原文地址:http://www.cnblogs.com/zhibao/p/7562816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!