组合数据类型练习,英文词频统计实例

本文提供了一系列简单的编程实例,包括凯撒密码加密、星座符号打印、格式化字符串输出、99乘法表展示、歌词单词统计及使用webbrowser模块打开网页等,适合编程初学者实践。

1、凯撒密码

复制代码
plaincode=input('明文:')
s=ord('a')
print('密文:',end='')
for i in plaincode:
    if s<= ord(i)<=ord('z'):
        print(chr(s+(ord(i)-s+3)%26),end='')
    else:
        print(i,end='')
    
复制代码

 

2、星座符号

for i in range(12):
    print(chr(9800+i),end='/')

 

 4、输入姓名,格式输出:占4位、居中、不足4字的以空格填充。

name=input('输入姓名:')
print('你的名字:{0:' '^4}'.format(name))

5、格式化输出:中华人民共和国国内生产总值(GDP)689,136.89亿元(2015年)(千分位、2位小数,浮点数)

 year = input("请输入年份:")
 gdp = float(input("请输入{}年的GDP:".format(year)))
 print("中华人民共和国国内生产总值(GDP){0:,.2f}亿元({1}年)".format(gdp,year))

6、实例:打出99乘法表

 

 for i in range(1,10):
     for j in range(1,10):
         print("{}x{}={}".format(i,j,i*j),end=' ')
         if i==j:
             print("\n")
             break

 

 

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

复制代码
geci = '''An empty street An empty house !
A hole inside heart? 
I'm all, alone and the rooms.
Are getting smaller 
I wonder how !I wonder why !
I wonder where they are 
geci=The !days we had .
The songs we sang together .
And oh! my love !
I'm holding on forever? ?
Reaching? for a love! 
That seems ?so far 
So I? say a litter prayer 
No my dream will take me there 
Where the skies are blue to see you 
once again my love 
Overseas from coast to coast 
Find, a place I love the most! 
Where the fields are green 
To see you once again  '''


print(geci.count('love'))
for i in geci:
    geci=geci.replace(',',' ')
    geci=geci.replace('.',' ')
    geci=geci.replace('!',' ')
    geci=geci.replace('?',' ')
print(geci)
print (geci.lower())
复制代码

 

 8、用webbrowser,uweb.open_new_tab('url')打开校园新闻列表

import webbrowser as web
for i in range(2,5):
    web.open_new_tab('http://news.gzcc.cn/html/xiaoyuanxinwen/'+str(i)+'.html')

转载于:https://www.cnblogs.com/45hjq/p/7562781.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值