• 欢迎光临~

python4

开发技术 开发技术 2022-09-28 次浏览

实例1、输出每日一贴

import datetime
mot=["今天星期一:n坚持下去不是因为我很坚强,而是因为我别无选择。",
"今天星期二:n含泪播种的人一定能笑着收获。",
"今天星期三:n做对的事比把事情做对重要。",
"今天星期四:n命运给予我们的不是失望之酒,而是机会之杯。",
"今天星期五:n不要等到明天,明天太遥远,今天就行动。",
"今天星期六:n求知若饥,虚心若愚。",
"今天星期日:n成功将属于那些从不说“不可能”的人。"]
day=datetime.datetime.now().weekday()
print(mot[day])

 python4

 

 实例2、分两列显示2017~2018赛季NBA西部联盟前八名的球队

print("2017~2018赛季NBA西部联盟前八名n")
team=["火箭","勇士","开拓者","雷霆","爵士","鹈鹕","马刺","森林狼"]
for index,item in enumerate(team):
if index%2==0:
print(item+"tt",end='')
else:
print(item+"n")

python4

 

 实例3、向NBA名人堂列表中追加2018年新进入的球星

oldlist=["迈克尔·乔丹","卡里姆·阿布杜尔·贾巴尔","哈基姆·奥拉朱旺","查尔斯·巴克利","姚明"]
newlist=["贾森·基德","史蒂夫·纳什","格兰特·希尔"]
oldlist.extend(newlist)
print(oldlist)

python4

 

 实例4、使用二维列表输出不同版式的古诗

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="")

python4

 

 实例5、使用元组保存咖啡馆里提供的咖啡名称

coffeename=('蓝山','卡布奇诺','曼特宁','摩卡','麝香猫','哥伦比亚')
print(coffeename)

python4

 

 实例6、使用for循环列出咖啡馆里的咖啡名称

coffeename=('蓝山','卡布奇诺','曼特宁','摩卡','麝香猫','哥伦比亚')
print("您好,欢迎光临~伊米咖啡馆~nn我店有:n")
for name in coffeename:
print(name+"咖啡t",end="")

 python4

 

 实例7、分两列显示2017~2018赛季NBA西部联盟前八名球队

print("2017~2018赛季NBA西部联盟前八名n")
team=("火箭","勇士","开拓者","雷霆","爵士","鹈鹕","马刺","森林狼")
for index,item in enumerate(team):
if index%2==0:
print(item+"tt",end='')
else:
print(item+"n")

python4

 

 实例8、将麝香猫咖啡替换为拿铁咖啡

coffeename=["蓝山","卡布奇诺","曼特宁","摩卡","麝香猫","哥伦比亚"]
coffeename[4]="拿铁"
print(coffeename)

python4

 

 实例9、创建一个保存女神星座的字典

name=['绮梦','冷伊一','香凝','黛兰']
sign=['水瓶座','射手座','双鱼座','双子座']
dictionary=dict(zip(name,sign))
print(dictionary)

python4

 

 实例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她的性格特点是:nn",sign_dict.get(person_dict.get("香凝")))

python4

 

 实例11、应用字典推导式实现根据名字和星座创建一个字典

name=['绮梦','冷伊一','香凝','黛兰']
sign=['水瓶','射手','双鱼','双子']
dictionary={i:j+'座' for i,j in zip(name,sign)}
print(dictionary)

python4

 

 实例12、创建保存学生选课信息的集合

python={'绮梦','冷伊一','香凝','梓轩'}
c={'冷伊一','零语','梓轩','圣博'}
print('选择Python语言的学生有:',python,'n')
print('选择C语言的学生有:',c)

python4

 

 实例13、学生更改选学课程

python=set(['绮梦','冷伊一','香凝','梓轩'])
python.add('零语')
c=set(['冷伊一','零语','梓轩','圣博'])
c.remove('零语')
print('选择Python语言的学生有:',python,'n')
print('选择C语言的学生有:',c)

python4

 

 实例14、对选课集合进行交集、并集和差集运算

python=set(['绮梦','冷伊一','香凝','梓轩'])
c=set(['冷伊一','零语','梓轩','圣博'])
print('选择Python语言的学生有:',python)
print('选择C语言的学生有:',c)
print('交集运算:',python&c)
print('并集运算:',python|c)
print('差集运算:',python-c)

python4

 

 实战1、输出“王者荣耀”的游戏角色

print("“王者荣耀”游戏角色:")
print('====坦克:====')
tanke=["苏烈","刘邦","钟馗","张飞","牛魔","程咬金","白起","刘禅","庄周","项羽","廉颇","巨灵神","安禄山","猪八戒"]
for i in tanke:
print(i,end=" ")
print("n"+"====战士:====")
zhanshi=["狂铁","裴擒虎","铠","孙悟空","哪吒","杨戬","橘右京","亚瑟","雅典娜","夏侯淳","关羽","吕布","韩信","老夫子","达摩","典韦","曹操","钟无艳","墨子","赵云","刑天","龙且"]
for i in zhanshi:
print(i,end=" ")
print("n"+"====刺客====")
cike=["百里玄策","庞统","花木兰","阿轲(荆轲)","不知火舞","李白","娜可露露","兰陵王","露娜","韩信","宫本","武藏","盖聂","红拂"]
for i in cike:
print(i,end=" ")
print("n"+"====法师:====")
fashi=["杨玉环","奕星","女娲","周瑜","鬼谷子","芈月","干将莫邪","东皇太一","大乔","诸葛亮","貂蝉","张良","安琪拉","不知火舞","姜子牙","武则天","王昭君","甄姬","扁鹊","高渐离","嬴政","妲己","小乔"]
for i in fashi:
print(i,end=" ")
print("n"+"====射手:=====")
sheshou=["公孙离","百里守约","后羿","刘备","黄忠","马可波罗","成吉思汗","虞姬","李元芳","艾琳","狄仁杰","鲁班七号","孙尚香"]
for i in sheshou:
print(i,end=" ")
print("n"+"====辅助:====")
fuzhu=["明世隐","梦奇","孙膑","太乙真人","蔡文姬"]
for i in fuzhu:
print(i,end=" ")

 python4

 

 实战2、模拟火车订票系统

a=["车次"," ","出发站—到达站"," ","出发时间"," ","到达时间"," ","历时"]
checi=["T40","T298","Z158","Z62"]
chufa_daoda=["长春—北京","长春—北京","长春—北京","长春—北京"]
kaishi_time=["00:12","00:06","12:48","21:58"]
daoda_time=["12:20","10:50","21:06","06:08"]
lishi=["12:08","10:44","08:18","8:20"]
for i in a:
print(i,end=" ")
print("n")
print(checi[0],' ',chufa_daoda[0],' ',kaishi_time[0],' ',daoda_time[0],' ',lishi[0],' ')
print(checi[1],' ',chufa_daoda[1],' ',kaishi_time[1],' ',daoda_time[1],' ',lishi[1],' ')
print(checi[2],' ',chufa_daoda[2],' ',kaishi_time[2],' ',daoda_time[2],' ',lishi[2],' ')
print(checi[3],' ',chufa_daoda[3],' ',kaishi_time[3],' ',daoda_time[3],' ',lishi[3],' ')
chufa_chx=dict(zip(checi,chufa_daoda))
kaishi_time_chx=dict(zip(checi,kaishi_time))
daoda_time_chx=dict(zip(checi,daoda_time))
lishi_chx=dict(zip(checi,lishi))
acheci=input("请输入购买车次:")
goumairen=input("请输入乘车人(用逗号分隔):")
achufa=chufa_chx[acheci]
print("你已购买"+acheci+"次列车"+achufa+"开,请"+goumairen+"尽快换取纸质车票。【铁路客服】")

 python4

 

 实战3、电视剧的收视率排行榜

a=[0,1,2,3,4,5,6,7,8,9]
TV=['《Give up,hold on to me》','《The private dishes of the husbands》','《My father-in-law will do martiaiarts》','《North Canton still believe in love》','《Impossible task》','《Sparrow》','《East of dream Avenue》','《The prodigal son of the new frontier town》','《Distant distance》','《Music legend》']
shoushi=['1.4%','1.343%','0.92%','0.862%','0.553%','0.411%','0.164%','0.259%','0.394%','0.562%']
a1 = dict(zip(shoushi,TV))
shoushi1 = sorted(shoushi,reverse = True)
a2 = dict(zip(a,shoushi1))
print('电视剧的收视率排行榜:')
none = True
b =0
while none:
print(a1.get(a2.get(b)),'收视率:',shoushi1[b])
b =b+1
if b==10:
break

 python4

 

 实战4、统计需要取快递人员的名单

a=set()
a1=set()
none=True
while none:
mingdan=str(input("请输入收到快递人员的名单(输入0退出):"))
if mingdan=='0':
none=False
break
a1.add(mingdan)
if len(a1)==len(a):
print("取快递人员已存在!")
a.add(mingdan)
print("需要通知取快递的人员名单:")
for item in a:
print(item)

python4

程序员灯塔
转载请注明原文链接:python4
喜欢 (0)