实例01:
import datetime
mot=["今天星期一:\n坚持下去不是因为我很坚强,而是因为我别无选择。",
"今天是星期二:\n含泪播种的人一定能笑着收获。",
"今天是星期三:\n做对的事情比把事情做对更重要。",
"今天是星期四:\n命运给予我们的不是失望之酒,而是机会之杯。",
"今天是星期五:\n不要等到明天,明天太遥远,今天就行动。",
"今天是星期六:\n求知若饥,虚心若愚。",
"今天是星期天:\n成功将属于那些不说“不可能”的人。"]
day=datetime.datetime.now().weekday()
print(mot[day])
实例02:
print("2017~2018赛季NBA西部联盟前八名\n")
team=["火箭","勇士","开拓者","雷霆","爵士","鹈鹕","马刺","森林狼"]
for index,item in enumerate(team):
if index%2==0:
print(item+"\t\t",end='')
else:
print(item+"\n")
实例03:
oldlist=["迈克尔·乔丹","卡里姆·阿布杜尔·贾巴尔","哈基姆·奥拉朱旺","查尔斯·巴格利","姚明"]
newlist=["贾森·基德","史蒂夫·纳什","格兰特·希尔"]
oldlist.extend(newlist)
print(oldlist)
实例04:
str1="千山鸟飞绝"
str2="万径人踪灭"
str3="孤舟蓑笠翁"
str4="独钓寒江雪"
verse=[list(str1),list(str2),list(str3),list(str4)]
print("\n--横版--\n")
for i in range(4):
for j in range(5):
if j==4:
print(verse[i][j])
else:
print(verse[i][j],end='')
verse.reverse()
print("\n--竖版--\n")
for i in range(5):
for j in range(4):
if j==3:
print(verse[j][i])
else:
print(verse[j][i],end='')
实例05:
coffeename=("蓝山","卡布奇诺","曼特宁","摩卡","麝香猫","哥伦比亚")
print(coffeename)
实例06:
coffeename=("蓝山","卡布奇诺","曼特宁","摩卡","麝香猫","哥伦比亚")
print("您好,欢迎光临~依米咖啡馆~\n\n我店有:\n")
for name in coffeename:
print(name+"咖啡",end=" ")
实例07:
print("2017~2018赛季NBA西部联盟前八名\n")
team=("火箭","勇士","开拓者","雷霆","爵士","鹈鹕","马刺","森林狼")
for index,item in enumerate(team):
if index%2==0:
print(item+"\t\t",end='')
else:
print(item+"\n")
实例08:
coffeename=("蓝山","卡布奇诺","曼特宁","摩卡","麝香猫","哥伦比亚")
coffeename=("蓝山","卡布奇诺","曼特宁","摩卡","拿铁","哥伦比亚")
print("新元组",coffeename)
实例09:
name=['依梦','冷伊一','香凝','黛兰']
sign=['水瓶座','射手座','双鱼座','双子座']
dictionary=dict(zip(name,sign))
print(dictionary)
实例10:
name=['绮梦','冷伊一','香凝','黛兰']
sign_person=['水瓶座','射手座','双鱼座','双子座']
person_dict=dict(zip(name,sign_person))
sign_all=['白羊座','金牛座','双子座','巨蟹座','狮子座','处女座','天秤座','天蝎座','射手座','摩羯座','水瓶座','双鱼座']
nature=['有一种让人看见就觉得开心的感觉,阳光,乐观,坚强,性格直来直去,有点小脾气。',
'很保守,喜欢稳定,一旦有什么变动会觉得心里不踏实,性格比较慢热,是个理财高手。',
'喜欢追求新鲜感,有点小聪明,耐心不够,因你的可爱性格会让很多人喜欢和你做朋友。',
'情绪容易敏感,缺乏安全感,做事情有坚持到底的毅力,为人重情重义,对朋友和家人特别忠实。',
'有着远大的理想,总是靠自己的努力去成为人上人,总是期待被仰慕被崇拜的感觉。',
'坚持追求自己的完美主义者。',
'追求平等、和谐,交际能力强,因此朋友比较多。最大得缺点就是面对选择犹豫不决。',
'精力旺盛,占有欲强,对于生活很有目标,不达目的不罢休,复仇心重。',
'崇尚自由,勇敢、果断、独立,身上有一股勇往直前的劲儿,只要想做,就能做。',
'是最有耐心的,做事最小心。做事脚踏实地,比较固执,不达目的不罢休,而且非常勤奋。',
'人很聪明,最大的特点就是创新,追求独一无二的生活,个人主义色彩很浓重的星座。',
'集所有星座的优缺点于一身,最大的优点就是有一颗善良的心,愿意帮助别人。']
sign_dict=dict(zip(sign_all,nature))
print("【香凝】的星座是",person_dict.get("香凝"))
print("\n她的性格特点是:\n\n",sign_dict.get(person_dict.get("香凝")))
实例11:
name=['绮梦','冷伊一','香凝','黛兰']
sign=['水瓶','射手','双鱼','双子']
dictionary={i:j+'座'for i,j in zip(name,sign)}
print(dictionary)
实例12:
python={'绮梦','冷伊一','香凝','梓轩'}
c={'冷伊一','零语','梓轩','圣博'}
print('选择Python语言的学生有:',python,'\n')
print('选择c语言的学生有:',c)
实例13:
python=set(['绮梦','冷伊一','香凝','梓轩'])
python.add('零语')
c=set(['冷伊一','零语','梓轩','圣博'])
c.remove('零语')
print('选择Python语言的学生有:',python,'\n')
print('选择c语言的学生有:',c)
实例14:
python=set(['绮梦','冷伊一','香凝','梓轩'])
c=set(['冷伊一','零语','梓轩','圣博'])
print('选择Python语言的学生有:',python)
print('选择c语言的学生有:',c)
print('交集运算:',python&c)
print('并集运算',python|c)
print('差集运算',python-c)
实战:
一,输出王者荣耀的游戏角色
print("“王者荣耀”游戏角色")
hero=["====坦克:====","苏烈 刘邦 钟馗","====战士:====","狂铁 凯 孙悟空","====刺客:====","李白 兰陵王 韩信",
"====法师:====","小乔 貂蝉 诸葛亮","====射手:====","鲁班 后羿 马可波罗","====辅助:====","明世隐 蔡文姬 孙膑"]
for item in hero:
print(item)
二,模拟火车订票系统
station=["车次","出发站-到达站","出发时间","到达时间","历时",
"T40","长春-北京","00:12","12:20","12:08",
"T298","长春-北京","00:06","10:50","10:44",
"Z158","长春-北京","12:48","21:06","08:18",
"Z62","长春-北京","21:58","06:08","8:20"]
for index,item in enumerate(station):
if(index+1)%5==0:
print(item+"\n")
else:
print(item+"\t\t",end='')
a=input("请输入要购买的车次:")
b=input("请输入乘车人(用逗号隔开):")
m=len(station)
for i in range(m):
if a==station[i]:
print("您已购",str(a)+"次列车"+station[i+1]+" "+station[i+2]+"开,请"+str(b)+"尽快换取纸质车票。【铁路客服】")
三,电视剧的收视率排行榜
listname = [('《Give up,hold on to me》',1.4),
('《The private dishes of the husbands》',1.343),
('《Sparrow》',0.411)]
listname = sorted(listname, key=lambda s: s[1], reverse=True)
print('电视剧的收视率排行榜:')
for item in listname:
print(item[0]+' 收视率:'+str(item[1])+'%')
四,统计需要快递人员的名单
i = 1
name = set()
while i:
key = input("请输入收到快递人员的名单(输入0退出): ")
if key == '0': #判断输入为0
i=0
print("需要通知取快递的人员名单:")
for j in name:
print(j)
elif key in name:
print("取快递人员已存在!")
else:
name.add(key)
标签:name,python,sign,item,实例,print,第四章 From: https://www.cnblogs.com/xwb123/p/16735624.html