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')