python-基础篇-列表和元组-脚本-结合生活-第一、基础

发布于:2024-04-18 ⋅ 阅读:(26) ⋅ 点赞:(0)

一、基础

6.1 管理QQ好友

# 6.1 管理QQ好友

fellow = ["编辑张震岳","周音讯","李国庆","李永民","温瑞安","司机帮","张老师","客服"]
print("***我的好友***")
print(fellow[0])
print(fellow[1])
print(fellow[2])
print(fellow[3])
print(fellow[4])
print(fellow[5])
print(fellow[6])
print(fellow[7])

在这里插入图片描述

在这里插入图片描述

6.2 添加和删除QQ好友

# 6.2 添加和删除QQ好友
fellow=["编辑张震岳","周音讯","李国庆","李永民","温瑞安","司机帮","张老师","客服"]
print("***我的好友***")
for item in fellow:
    print(item)
print("***我的好友***")
fellow.remove("司机帮")
fellow.remove("客服")
for item in fellow:
    print(item)
print("***我的好友***")
fellow.append("郭帆")
fellow.append("吴孟达")
for item in fellow:
    print(item)

在这里插入图片描述

在这里插入图片描述

6.3 模拟QQ好友添加辅助信息

# 6.3 模拟QQ好友添加辅助信息

fellow=["编辑张震岳","周音讯","李国庆","李永民","温瑞安","司机帮","张老师","客服"]
print("***我的好友***")
fellow[0] = fellow[0] + "   Svip"
fellow[1] = fellow[1] + "   Svip"
fellow[2] = fellow[2] + "   Svip"
fellow[3] = fellow[3] + "   Svip"
fellow[4] = fellow[4] + "   vip"
fellow[5] = fellow[5] + "   vip"

for item in fellow:
    print(item)

在这里插入图片描述

6.4 统计QQ好友并排序

# 6.4 统计QQ好友并排序

fellow=["编辑张震岳","周音讯","李国庆","李永民","温瑞安","司机帮","张老师","客服"]
print("***我的好友***")
print("我的好友共有:" , len(fellow) , "人")
fellow.sort()
print(fellow)
fellow.sort(reverse=True)
print(fellow)

在这里插入图片描述

6.5 为歌曲库添加歌手信息

# 6.5 为歌曲库添加歌手信息

mysong = input("请输入你喜欢的歌曲:")
mylist = [mysong]
mysong = input("请输入你喜欢的歌曲:")
mylist.append(mysong)
mysong = input("请输入你喜欢的歌曲:")
mylist.append(mysong)
mysong = input("请输入你喜欢的歌曲:")
mylist.append(mysong)
mysong = input("请输入你喜欢的歌曲:")
mylist.append(mysong)
print(mylist)
mylist[1] = mylist[1] + "   成龙"
print(mylist)

在这里插入图片描述

6.6 世界那么大,我想去看看

# 6.6 世界那么大,我想去看看

import random
world = ["西北", "中国", "亚洲", "世界"]
print(world[random.choice([0, 1, 2, 3])] + "那么大,我想去看看!!")
name = ["郭帆", "郭帆与儿子", "郭帆一家人", "郭帆和同学"]
print("世界那么大,", name[random.choice([0, 1, 2, 3])], "想去看看!!")

在这里插入图片描述

6.7 输入输出杭黄高铁的沿线高铁站

# 6.7 输入输出杭黄高铁的沿线高铁站


# 简单版
station=["杭州东","杭州南","富阳","桐庐","建德东","千岛湖","三阳","绩溪北","歙县北","黄山北"]
print("D5587列车途径以下各站:")
for item in station:
     print(item +">",end="")
print("\n"+ 70* "*")
print("D5588列车途径以下各站:")
station.reverse()   #对高铁站列表反向输出
for item in station:
     print(item+">",end="")
print("\n"+ 70* "*")
station.reverse()  #对高铁站列表恢复正向输出
print("黎明需要途径以下高铁站:")
liming=station[0:6]
print(liming)
print("黎明需要乘坐 %d"%len(liming)+" 站高铁!!")


在这里插入图片描述



# 超纲版
station = ["杭州东","杭州南","富阳","桐庐","建德东","千岛湖","三阳","绩溪北","歙县北","黄山北"]

print("D5587列车途径以下各站:")
for item in station:
     print(item + ">", end="")
print("\n" + 70 * "*")

print("D5588列车途径以下各站:")
station.reverse()
for item in station:
     print(item + ">",end="")
print("\n" + 70 * "*")

print("D5587列车途径以下各站:")
station.reverse()
i = 0
for item in station:
    i = i + 1
    print(item + ",")
    if item == "千岛湖":
        break
print("需要经过", i, "站下车\n" + 70 * "*")

在这里插入图片描述

6.8 模拟车牌号码选择

# 6.8 模拟车牌号码选择

plate_nunber=["澳C-KM516","澳C-GN516","澳C-KD516","澳C-EV516","澳C-EG516","澳C-KB516","澳C-QU516","澳C-VG516","澳C-QG516","澳C-NE516"]
print("您所选号牌已被使用,有如下相似号牌可供使用:")
for item in plate_nunber:
     print(item)
print( "")
print(100 * "*")
print("您选中了号牌:澳C-GN516")
plate_nunber.remove("澳C-GN516")
print("剩余相似号牌为:" + str(len(plate_nunber)) + "个,号牌为:")

for item in plate_nunber:
     print(item)

print( "")
print(100 * "*")
print("您选中了号牌:澳C-QU516")
plate_nunber.remove("澳C-QU516")
print("剩余相似号牌为:" + str(len(plate_nunber)) + "个,号牌为:")
for item in plate_nunber:
     print(item)
print( "")
print(100 * "*")
print("您选中了号牌:澳C-KM516")
plate_nunber.remove("澳C-KM516")
print("剩余相似号牌为:" + str(len(plate_nunber)) + "个,号牌为:")
for item in plate_nunber:
     print(item)

在这里插入图片描述

6.9 模拟淘宝的菜单组合功能

# 6.9 模拟淘宝的菜单组合功能


menu1 = ["我的淘宝", "购物车", "收藏夹", "商品分类", "卖家中心", "联系客服"]
menu2 = ["中国大陆", "亲,请登录", "免费注册", "手机逛淘宝"]
menu3 = ["中国大陆", "明日科技", "消息", "手机逛淘宝"]
menu2 = menu2 + menu1
for item in menu2:
     print(item + "  ", end="")
print("\n" + 100 * "*")
menu3 = menu3 + menu1
for item in menu3:
     print(item + "  ", end="")
print("\n" + 100 * "*")

在这里插入图片描述

6.10 模拟重庆江北机场T2航站楼国内出发部分航空公司指示

# 6.10 模拟重庆江北机场T2航站楼国内出发部分航空公司指示

isle_f=[["国航","CA"],["深航","ZH"],["山航","SC"],["鲲鹏","VD"],["昆航","KY"]]
isle_e=[["厦航","MF"],["奥凯","BK"],["华夏","C5"],["春秋","9C"],["吉祥","HQ"],["河北","NS"]]
isle_d=[["东航","MU"],["上航","FM"],["联航","KN"]]
isle_c=[["南航","CZ"],["重庆","OQ"]]
isle_b=[["西部","PN"],["海航","HU"],["金鹿","JD"],["祥鹏","8L"],["天津","GS"]]
isle_a=[["川航","3U"],["成都","EU"]]
isle=[ "A岛","B岛" ,"C岛","D岛","E岛" ,"F岛" ]
print(isle[0] + ":", end="")
for item in isle_a:
     print(item[0] +"--"+ item[1] + "   ",end="")
print(" ")
print(isle[1]+ ":", end="")

for item in isle_b:
     print(item[0] +"--"+ item[1] + "   ",end="")
print(" ")

print(isle[2] + ":", end="")
for item in isle_c:
     print(item[0] +"--"+ item[1] + "   ",end="")
print(" ")

print(isle[3] + ":", end="")
for item in isle_d:
     print(item[0] +"--"+ item[1] + "   ",end="")
print(" ")

print(isle[4]+ ":", end="")
for item in isle_e:
     print(item[0] +"--"+ item[1] + "   ",end="")
print(" ")
print(isle[5] + ":", end="")
for item in isle_f:
     print(item[0] +"--"+ item[1] + "   ",end="")
print(" ")

在这里插入图片描述