python小项目

python小项目,第1张

🌞欢迎来到python的世界 
🌈博客主页:卿云阁

💌欢迎关注🎉点赞👍收藏⭐️留言📝

🌟本文由卿云阁原创!

🌠本阶段属于练气阶段,希望各位仙友顺利完成突破

📆首发时间:🌹2021年4月30日🌹

✉️希望可以和大家一起完成进阶之路!

🙏作者水平很有限,如果发现错误,请留言轰炸哦!万分感谢!


目录

🍈 一、快递分练小程序

 🍉二. 综合实战-股票数据分析&处理

 🍉二. 炸金花

 

🍈 一、快递分练小程序
  • 数据源为嵌套列表
  • 结果为字典样式,key为省份,value为嵌套列表
  • 取前三字符判断是否可行,特殊区域特殊处理

1.嵌套列表

infos=[
    ['王*龙', '北京市海淀区4层'],
    ['庞*飞', '北京市昌平区四楼403'],
]
print(infos[0])
print(infos[0][0])

结果
['王*龙', '北京市海淀区4层']
王*龙

 2.切片的进阶

 

# -*- coding: utf-8 -*-
infos=[
    ['王*龙', '北京市海淀区4层'],
    ['庞*飞', '北京市昌平区四楼403'],
    ['顾*锐', '江苏省扬州市畜禽有限公司'],
    ['王*飞', '上海市徐汇区广场B座5E'],
    ['华*升', '北京市海淀区大厦'],
    ['朱*锴', '上海市浦东新区'],
    ['陈*盼', '浙江省杭州市闲林'],
    ['司*鹏', '河南省鹤壁市'],
    ['聂*睿', '河北省石家庄市'],
]
results = {}
others = ['新疆','宁夏']
print("-----分练开始-----")
for info in infos:
    province = info[1][:3]
    if info[1][:2] in others:
        province = info[1][:2]
    if province in results:
        results[province].append(info)
    else:
        results[province] = [info]
print('{')
for province in results:
    print(f"\t'{province}':[")
    for value in results[province]:
        print(f"\t\t{value},")
    print(f"\t],")
print('}')
结果:
-----分练开始-----
{
	'北京市':[
		['王*龙', '北京市海淀区4层'],
		['庞*飞', '北京市昌平区四楼403'],
		['华*升', '北京市海淀区大厦'],
	],
	'江苏省':[
		['顾*锐', '江苏省扬州市畜禽有限公司'],
	],
	'上海市':[
		['王*飞', '上海市徐汇区广场B座5E'],
		['朱*锴', '上海市浦东新区'],
	],
	'浙江省':[
		['陈*盼', '浙江省杭州市闲林'],
	],
	'河南省':[
		['司*鹏', '河南省鹤壁市'],
	],
	'河北省':[
		['聂*睿', '河北省石家庄市'],
	],
}
 🍉二. 综合实战-股票数据分析&处理 把以下股票数据存⼊ stock_data.txt 开发程序对 stock_data.txt 进⾏以下 *** 作: 1. 程序启动后,给⽤户提供查询接⼝,允许⽤户᯿复查股票⾏情信息 ( ⽤到循环 ) 2. 允许⽤户通过模糊查询股票名,⽐如输⼊ 啤酒 ”, 就把所有股票名称中包含 啤酒 的信息打印出来 3. 允许按股票价格、涨跌幅、换⼿率这⼏列来筛选信息,⽐如输⼊ 价格 >50” 则把价格⼤于 50 的股票 都打印,输⼊ 市盈率 <50“ ,则把市盈率⼩于 50 的股票都打印,不⽤判断等于。 思路提示:加载⽂件内容到内存,转成 dict or list 结构,然后对 dict or list 进⾏查询等 *** 作。 这样以后 就不⽤每查⼀次就要打开⼀次⽂件了,效率会⾼。
# 1. 程序启动后,给用户提供查询接口,允许用户**重复查**股票行情信息。
#
import re

stock_dic = {}
f = open("stock_data.txt", encoding="utf-8")

headers = f.readline().strip().split(",")

for line in f:
    line = line.strip().split(",")
    stock_dic[line[0]] = line
f.close()

# for i,j in stock_dic.items():
#     print(i,j)


while True:
    cmd = input("请输入要查询的股票指令")

    for s_id, s_data in stock_dic.items():
        s_name = s_data[1]
        if cmd in s_name:
            print(s_data)

    # if cmd == "退出":
    #     break

# 2. 允许用户通过**模糊查询**股票名,比如输入“啤酒”,
# 就把所有名称当中包含啤酒的股票都打印出来。
#
# 3. 允许按 **当前价、涨跌幅、换手率**这几列来筛选信息,
# 比如输入**“当前价>50**”则把价格大于50的股票都打印,
# 输入“**涨跌幅<50**“,则把涨跌幅小于50的股票都打印,不用判断等于。

# 格式是否合法(正则表达式)
    cmd_parser = re.split("[<>]", cmd)
    if len(cmd_parser) != 2:
        continue

# 列名是否合法
    filter_column, filter_val = cmd_parser
    if filter_column not in ["当前价", "涨跌幅", "换手率"]:
        continue

# 数值的合法性
    try:
        filter_val = float(filter_val)
    except ValueError:
        continue

# 根据列名,找到想查的列的索引
    column_index = headers.index(filter_column)

    for s_id, s_data in stock_dic.items():
        if ">" in cmd:
            if float(s_data[column_index].strip("%")) > filter_val:
                print(s_data)
        else:
            if float(s_data[column_index].strip("%")) < filter_val:
                print(s_data)




结果
请输入要查询的股票指令N晶科
['SH601778', 'N晶科', '6.29', '+1.92', '+43.94%', '+43.94%', '259.66万', '1625.52万', '0.44%', '22.32', '-', '173.95亿']
请输入要查询的股票指令

 

数据源已经帮你准备好了 stock_data.txt
股票代码,股票名称,当前价,涨跌额,涨跌幅,年初⾄今,成交量,成交额,换⼿率,市盈率(TTM),股息率,市 值
SH601778,N晶科,6.29,+1.92,+43.94%,+43.94%,259.66万,1625.52
万,0.44%,22.32,-,173.95亿
SH688566,吉⻉尔,52.66,+6.96,+15.23%,+122.29%,1626.58万,8.09
亿,42.29%,89.34,-,98.44亿
SH688268,华特⽓体,88.80,+11.72,+15.20%,+102.51%,622.60万,5.13
亿,22.87%,150.47,-,106.56亿
SH600734,实达集团,2.60,+0.24,+10.17%,-61.71%,1340.27万,3391.14万,2.58%,亏 损,0.00%,16.18亿
SH900957,凌云B股,0.36,+0.033,+10.09%,-35.25%,119.15万,42.10
万,0.65%,44.65,0.00%,1.26亿
SZ000584,哈⼯智能,6.01,+0.55,+10.07%,-4.15%,2610.86万,1.53
亿,4.36%,199.33,0.26%,36.86亿
SH600599,熊猫⾦控,6.78,+0.62,+10.06%,-35.55%,599.64万,3900.23万,3.61%,亏 损,0.00%,11.25亿
SH600520,⽂⼀科技,8.21,+0.75,+10.05%,-24.05%,552.34万,4464.69万,3.49%,亏 损,0.00%,13.01亿
SH603682,锦和商业,11.73,+1.07,+10.04%,+48.29%,2746.63万,3.15
亿,29.06%,29.62,-,55.42亿
SZ300831,派瑞股份,12.27,+1.12,+10.04%,+208.29%,25.38万,311.41
万,0.32%,60.59,-,39.26亿
SH900939,汇丽B,0.504,+0.046,+10.04%,-23.52%,123.86万,61.86
万,1.41%,52.80,0.00%,9147.60万
SH600880,博瑞传播,4.39,+0.40,+10.03%,+10.03%,1117.75万,4816.57
万,1.02%,95.87,0.50%,48.00亿
SZ000609,中迪投资,7.68,+0.70,+10.03%,+39.64%,2663.08万,2.00
亿,9.12%,58.84,0.00%,22.98亿
SZ300328,宜安科技,15.80,+1.44,+10.03%,+7.19%,432.45万,6832.68
万,0.95%,64.80,0.51%,72.72亿
SZ002988,豪美新材,17.33,+1.58,+10.03%,+58.41%,3.50万,60.68万,0.06%,24.42,-,40.34
亿
SZ000615,京汉股份,4.61,+0.42,+10.02%,+4.06%,518.09万,2388.41万,0.69%,亏 损,0.00%,36.06亿
SZ300443,⾦雷股份,18.33,+1.67,+10.02%,+32.74%,987.25万,1.75
亿,6.19%,18.78,1.08%,43.64亿
SH600506,⾹梨股份,11.42,+1.04,+10.02%,+11.96%,1039.48万,1.18亿,7.04%,亏 损,0.00%,16.87亿
SZ300505,川⾦诺,15.61,+1.42,+10.01%,-11.26%,493.54万,7555.40
万,6.03%,26.70,0.85%,20.40亿
SZ300830,⾦现代,14.95,+1.36,+10.01%,+239.77%,63.66万,951.76
万,0.74%,70.76,0.00%,64.30亿
SH603630,拉芳家化,17.26,+1.57,+10.01%,+27.85%,949.49万,1.60
亿,4.19%,209.44,0.83%,39.13亿
SZ002655,共达电声,11.43,+1.04,+10.01%,-14.64%,1683.51万,1.88
亿,4.68%,166.69,0.00%,41.15亿
SZ300460,惠伦晶体,16.59,+1.51,+10.01%,+0.97%,430.28万,6974.52万,2.56%,亏 损,0.00%,27.92亿
SH603929,亚翔集成,20.33,+1.85,+10.01%,+33.40%,1373.66万,2.76
亿,6.44%,84.29,1.25%,43.38亿
SH603392,万泰⽣物,35.97,+3.27,+10.00%,+311.09%,6.92万,248.91
万,0.16%,65.24,-,155.97亿
SZ000788,北⼤医药,6.82,+0.62,+10.00%,+2.40%,832.44万,5583.87
万,1.40%,89.69,0.32%,40.65亿
SH601609,⾦⽥铜业,10.89,+0.99,+10.00%,+66.26%,4027.64万,4.28
亿,16.64%,32.38,0.32%,158.66亿
SZ000403,双林⽣物,52.48,+4.77,+10.00%,+62.48%,171.75万,9013.54
万,0.63%,88.80,0.23%,143.05亿
SZ300832,新产业,72.80,+6.62,+10.00%,+131.92%,10.73万,780.85
万,0.26%,40.20,0.62%,299.64亿
SZ002985,北摩⾼科,92.58,+8.42,+10.00%,+310.92%,2422.97万,21.55
亿,64.54%,60.48,1.08%,139.02亿
SH603348,⽂灿股份,18.06,+1.64,+9.99%,-25.15%,357.86万,6328.87
万,4.39%,89.39,0.89%,41.83亿
SH603900,莱绅通灵,8.92,+0.81,+9.99%,-5.61%,1364.10万,1.15
亿,4.01%,43.78,5.06%,30.37亿
SH603042,华脉科技,17.85,+1.62,+9.98%,+17.05%,491.44万,8705.99
万,4.86%,128.50,0.31%,24.28亿
SZ300260,新莱应材,19.83,+1.80,+9.98%,+68.48%,1800.45万,3.48
亿,14.16%,65.15,0.73%,40.04亿
SZ000557,⻄部创业,3.42,+0.31,+9.97%,-0.87%,2751.17万,9408.89
万,1.89%,79.39,0.00%,49.88亿
SZ300716,国⽴科技,9.94,+0.90,+9.96%,-4.24%,142.25万,1413.92万,1.50%,亏 损,0.29%,15.91亿
SZ002449,国星光电,11.92,+1.08,+9.96%,-6.80%,5185.52万,6.03
亿,8.53%,21.51,2.73%,73.72亿
SZ002397,梦洁股份,8.50,+0.77,+9.96%,+73.47%,810.06万,6885.51
万,1.67%,110.68,2.35%,64.95亿
SZ002662,京威股份,4.09,+0.37,+9.95%,+54.92%,8588.12万,3.40亿,5.89%,亏 损,0.00%,61.35亿
SZ002297,博云新材,6.30,+0.57,+9.95%,-1.87%,2852.27万,1.74亿,6.07%,亏 损,0.00%,29.69亿
SZ300351,永贵电器,8.62,+0.78,+9.95%,-2.16%,1443.26万,1.23亿,5.89%,亏 损,0.00%,33.07亿
SH600834,申通地铁,7.63,+0.69,+9.94%,+5.68%,223.20万,1703.02
万,0.47%,74.74,0.56%,36.42亿
SZ000616,海航投资,3.10,+0.28,+9.93%,+27.57%,5002.95万,1.51
亿,3.50%,133.28,0.00%,44.34亿
SH600662,强⽣控股,5.54,+0.50,+9.92%,+22.03%,254.89万,1412.07万,0.24%,亏 损,0.72%,58.36亿
SZ300223,北京君正,107.20,+8.92,+9.08%,+23.01%,930.81万,9.86
亿,7.34%,314.71,0.00%,216.28亿
SZ002978,安宁股份,35.46,+2.95,+9.07%,+29.09%,1181.96万,4.11
亿,29.10%,25.11,-,142.31亿
SZ002084,海鸥住⼯,7.09,+0.54,+8.24%,+9.24%,1647.83万,1.16
亿,3.36%,33.83,0.00%,35.60亿
SH688012,中微公司,229.00,+17.30,+8.17%,+147.84%,448.32万,10.05
亿,8.72%,607.21,-,1224.83亿
SZ002049,紫光国微,74.04,+5.54,+8.09%,+45.63%,4459.03万,32.57
亿,7.35%,85.03,0.10%,449.29亿
SH600329,中新药业,14.83,+1.10,+8.01%,+7.00%,1159.16万,1.68
亿,2.05%,18.90,2.16%,114.61亿
SZ002204,⼤连᯿⼯,5.71,+0.41,+7.74%,+77.88%,1.73亿,9.35
亿,8.97%,213.83,0.55%,110.28亿
SH688088,虹软科技,84.16,+5.96,+7.62%,+78.12%,290.59万,2.43
亿,7.22%,148.96,-,341.69亿
SZ300398,⻜凯材料,21.33,+1.50,+7.56%,+42.68%,2676.82万,5.65
亿,6.21%,47.18,0.00%,110.41亿
SZ300298,三诺⽣物,21.93,+1.53,+7.50%,+48.45%,832.56万,1.80
亿,1.89%,46.66,1.44%,123.97亿
SH603236,移远通信,235.40,+16.09,+7.34%,+61.34%,96.10万,2.22
亿,4.31%,151.64,0.22%,209.93亿
SZ002074,国轩⾼科,26.93,+1.79,+7.12%,+85.09%,3628.58万,9.54亿,3.60%,亏 损,0.00%,304.25亿
SZ000710,⻉瑞基因,51.27,+3.37,+7.04%,+40.08%,411.57万,2.09
亿,2.91%,63.69,0.00%,181.81亿
SZ300624,万兴科技,95.86,+6.28,+7.01%,+51.92%,374.27万,3.54
亿,7.52%,84.07,0.38%,77.91亿
SZ300002,神州泰岳,6.42,+0.41,+6.82%,+96.93%,9118.57万,5.66亿,5.59%,亏 损,0.00%,126.10亿
SH603012,创⼒集团,7.30,+0.46,+6.73%,-18.16%,2648.28万,1.92
亿,4.16%,15.57,1.01%,46.47亿
SZ300144,宋城演艺,31.70,+1.98,+6.66%,+2.56%,980.92万,3.08
亿,0.82%,45.22,0.66%,460.77亿
SZ300724,捷佳伟创,67.58,+4.18,+6.59%,+78.36%,223.02万,1.48
亿,1.31%,57.75,0.28%,216.70亿
SZ200706,瓦轴B,2.27,+0.14,+6.57%,-21.99%,25.88万,57.83万,0.16%,亏损,0.00%,9.18亿
SH603693,江苏新能,12.10,+0.74,+6.51%,+18.86%,2377.38万,2.87
亿,12.32%,19.47,1.32%,74.78亿
SZ200468,宁通信B,1.82,+0.11,+6.43%,-26.32%,53.22万,96.40万,0.53%,亏损,0.00%,3.89
亿
SH600426,华鲁恒升,18.11,+1.09,+6.40%,-8.86%,1369.76万,2.46
亿,0.85%,13.16,2.05%,294.59亿
SH900953,凯⻢B,0.334,+0.020,+6.37%,-30.13%,186.93万,63.29
万,0.78%,236.41,0.00%,2.14亿
SH600703,三安光电,25.15,+1.50,+6.34%,+36.98%,1.08亿,26.73
亿,2.65%,95.77,0.42%,1025.72亿
SZ300118,东⽅⽇升,12.75,+0.74,+6.16%,-7.94%,3686.23万,4.68
亿,5.29%,13.57,1.63%,114.92亿
SZ300418,昆仑万维,22.25,+1.29,+6.15%,+32.84%,3641.22万,8.00
亿,4.03%,18.07,0.12%,257.36亿
SH900929,锦旅B股,1.214,+0.070,+6.12%,-25.52%,36.05万,43.02
万,0.55%,19.81,0.00%,1.61亿
SZ300496,中科创达,60.79,+3.49,+6.09%,+34.99%,1062.96万,6.40
亿,3.75%,96.33,0.22%,244.69亿
SH600818,中路股份,12.36,+0.71,+6.09%,+3.69%,921.26万,1.15亿,3.87%,亏 损,0.00%,39.73亿
SZ300644,南京聚隆,35.19,+2.01,+6.06%,+18.64%,872.06万,3.12
亿,21.10%,79.62,0.55%,22.53亿
SZ300729,乐歌股份,24.18,+1.38,+6.05%,+3.50%,204.82万,4889.15
万,8.14%,31.62,1.31%,21.09亿
SZ300767,震安科技,108.58,+6.16,+6.01%,+79.44%,146.41万,1.57
亿,3.19%,92.38,0.21%,86.86亿
SH603179,DR新泉股,19.30,+1.08,+5.93%,+35.50%,147.38万,2833.24
万,0.65%,35.11,2.25%,56.76亿
SH603626,科森科技,11.27,+0.63,+5.92%,+8.47%,466.11万,5187.87万,1.01%,亏 损,0.00%,53.30亿
SZ300019,硅宝科技,9.50,+0.53,+5.91%,-6.13%,423.46万,3943.10
万,1.55%,24.58,1.65%,31.40亿
SZ002756,永兴材料,16.18,+0.90,+5.89%,-7.34%,247.83万,3910.01
万,1.34%,18.38,2.98%,58.21亿
SZ002498,汉缆股份,6.11,+0.34,+5.89%,+102.99%,2.01亿,12.04
亿,6.05%,43.98,0.62%,202.93亿
SZ002980,华盛昌,62.41,+3.46,+5.87%,+319.14%,969.65万,5.99亿,29.09%,51.97,-,83.21
亿
SZ002371,北⽅华创,176.88,+9.80,+5.87%,+101.00%,1006.35万,17.45
亿,2.20%,276.58,0.04%,875.76亿
SZ300139,晓程科技,8.71,+0.48,+5.83%,+0.23%,4423.87万,3.82亿,20.11%,亏 损,0.00%,23.84亿
SZ000636,⻛华⾼科,24.51,+1.33,+5.74%,+64.61%,5605.61万,13.61
亿,6.26%,71.71,0.00%,219.42亿
SZ000564,供销⼤集,4.06,+0.22,+5.73%,+69.87%,2.98亿,11.89亿,14.86%,亏 损,0.00%,244.52亿
SZ002612,朗姿股份,7.84,+0.42,+5.66%,-19.34%,540.71万,4191.22
万,2.31%,1224.17,4.23%,34.69亿
SH600176,中国巨⽯,9.39,+0.50,+5.62%,-13.85%,3256.19万,3.02
亿,0.93%,16.97,2.14%,328.87亿
SH603313,梦百合,24.10,+1.28,+5.61%,+14.16%,356.10万,8446.14
万,1.05%,21.72,0.00%,82.23亿
SZ300279,和晶科技,5.49,+0.29,+5.58%,-8.50%,2328.20万,1.31亿,5.33%,亏 损,0.00%,24.65亿
 🍉二. 炸金花
# 一付扑克牌,去掉大小王,每个玩家发3张牌,最后比大小,看谁赢。
#
# 有以下几种牌:
#
# 豹子:三张一样的牌,如3张6.
#
# 顺金:又称同花顺,即3张同样花色的顺子, 如红桃 5、6、7
#
# 顺子:又称拖拉机,花色不同,但是顺子,如红桃5、方片6、黑桃7,组成的顺子
#
# 对子:2张牌一样
#
# 单张:单张最大的是A
#
# 这几种牌的大小顺序为, **豹子>顺金>同花>顺子>对子>单张**


# 单牌之间如何比大小
# A:红桃J 红桃K 黑桃A  11 + 130 + 1400 = 1541
# B:方片2 方片2 梅花3  2 + 20 + 300 = 322 * 10 = 3220

# 不同牌型之间如何比大小
# 如何判断玩家是什么牌(不同牌型有不同的判断方法) 高内聚 低耦合
import random


# 1, 生成牌
def generate_pokes():
    poke_types = ["♥", "♠", "♣", "♦"]
    poke_nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K", "A"]
    poke_list = []
    for p_type in poke_types:
        count = 2
        for p_num in poke_nums:
            card = [f"{p_type}{p_num}", count]
            count += 1
            poke_list.append(card)
    return poke_list


poke_list = generate_pokes()
random.shuffle(poke_list)
players = ["old_shang", "alex", "peiqi", "智哥", "小芸"]


# 2, 发牌
def issue_cards(players, poke_list):
    player_dic = {}

    for p_name in players:
        p_cards = random.sample(poke_list, 3)
        for card in p_cards:
            poke_list.remove(card)
        player_dic[p_name] = p_cards
        print(f"为玩家{p_name}生成了牌", p_cards)
    return player_dic


player_dic = issue_cards(players, poke_list)


# 3,写好每种牌型的规则函数

def sortlist(lis):
    # 冒泡排序
    l = len(lis)
    for i in range(0, l):
        for j in range(0, l - i - 1):
            if lis[j][1] > lis[j + 1][1]:
                lis[j], lis[j + 1] = lis[j + 1], lis[j]
    return lis


# 单牌
def calculate_single(p_cards, score):

    p_cards = sortlist(p_cards)
    weight_val = [0.1, 1, 10]
    count = 0
    for card in p_cards:
        score += card[1] * weight_val[count]
        count += 1
    print("计算单牌", p_cards, score)
    return score


# 对子
def calculate_pair(p_cards, score):
    p_cards = sortlist(p_cards)
    card_val = [i[1] for i in p_cards]
    if len(set(card_val)) == 2:
        if card_val[0] == card_val[1]:
            score = (card_val[0] + card_val[1]) * 50 + card_val[2]
        else:
            score = (card_val[2] + card_val[1]) * 50 + card_val[0]
    print("计算对子", p_cards, score)
    return score


# 顺子
def calculate_straight(p_cards, score):
    p_cards = sortlist(p_cards)
    card_val = [i[1] for i in p_cards]
    a, b, c = card_val
    if (b - a == 1 and c - b == 1) or card_val == [2, 3, 14]:
        score *= 100
    print("计算顺子", p_cards, score)
    return score

# 同花
def calculate_same_color(p_cards, score):
    color_set = {i[0][0] for i in p_cards}
    if len(color_set) == 1:
        score *= 1000
    print("计算同花", p_cards, score)
    return score

# 同花顺
def calculate_same_color_straight(p_cards, score):
    p_cards = sortlist(p_cards)
    card_val = [i[1] for i in p_cards]
    a, b, c = card_val
    if (b - a == 1 and c - b == 1) or card_val == [2, 3, 14]:
        color_set = {i[0][0] for i in p_cards}
        if len(color_set) == 1:
            score *= 0.1
    print("计算同花顺", p_cards, score)
    return score
# 豹子
def calculate_leopard(p_cards, score):
    card_val = {i[1] for i in p_cards}
    if len(card_val) == 1:
        score *= 100000
    print("计算豹子", p_cards, score)
    return score

# 4,对比

calc_func_orders = [
    calculate_single,
    calculate_pair,
    calculate_straight,
    calculate_same_color,
    calculate_same_color_straight,
    calculate_leopard
]


performance = []

for p_name, p_cards in player_dic.items():
    print(f"开始计算玩家{p_name}的牌")
    score = 0
    for calc_fun in calc_func_orders:
        score = calc_fun(p_cards, score)
    performance.append([p_name, score])
print(performance)

winner = sortlist(performance)[-1]
for i in performance:
    if int(i[1]) == int(winner[1]):
        print("赢家是", i)



while True:
    cmd = input("请输入要查询的股票指令")

    for s_id, s_data in stock_dic.items():
        s_name = s_data[1]
        if cmd in s_name:
            print(s_data)

    # if cmd == "退出":
    #     break

# 2. 允许用户通过**模糊查询**股票名,比如输入“啤酒”,
# 就把所有名称当中包含啤酒的股票都打印出来。
#
# 3. 允许按 **当前价、涨跌幅、换手率**这几列来筛选信息,
# 比如输入**“当前价>50**”则把价格大于50的股票都打印,
# 输入“**涨跌幅<50**“,则把涨跌幅小于50的股票都打印,不用判断等于。

# 格式是否合法(正则表达式)
    cmd_parser = re.split("[<>]", cmd)
    if len(cmd_parser) != 2:
        continue

# 列名是否合法
    filter_column, filter_val = cmd_parser
    if filter_column not in ["当前价", "涨跌幅", "换手率"]:
        continue

# 数值的合法性
    try:
        filter_val = float(filter_val)
    except ValueError:
        continue

# 根据列名,找到想查的列的索引
    column_index = headers.index(filter_column)

    for s_id, s_data in stock_dic.items():
        if ">" in cmd:
            if float(s_data[column_index].strip("%")) > filter_val:
                print(s_data)
        else:
            if float(s_data[column_index].strip("%")) < filter_val:
                print(s_data)




结果
为玩家old_shang生成了牌 [['♠A', 14], ['♠5', 5], ['♦K', 13]]
为玩家alex生成了牌 [['♦5', 5], ['♣5', 5], ['♦10', 10]]
为玩家peiqi生成了牌 [['♦Q', 12], ['♣9', 9], ['♣K', 13]]
为玩家智哥生成了牌 [['♥K', 13], ['♦9', 9], ['♠6', 6]]
为玩家小芸生成了牌 [['♠K', 13], ['♥10', 10], ['♥8', 8]]
开始计算玩家old_shang的牌
计算单牌 [['♠5', 5], ['♦K', 13], ['♠A', 14]] 153.5
计算对子 [['♠5', 5], ['♦K', 13], ['♠A', 14]] 153.5
计算顺子 [['♠5', 5], ['♦K', 13], ['♠A', 14]] 153.5
计算同花 [['♠5', 5], ['♦K', 13], ['♠A', 14]] 153.5
计算同花顺 [['♠5', 5], ['♦K', 13], ['♠A', 14]] 153.5
计算豹子 [['♠5', 5], ['♦K', 13], ['♠A', 14]] 153.5
开始计算玩家alex的牌
计算单牌 [['♦5', 5], ['♣5', 5], ['♦10', 10]] 105.5
计算对子 [['♦5', 5], ['♣5', 5], ['♦10', 10]] 510
计算顺子 [['♦5', 5], ['♣5', 5], ['♦10', 10]] 510
计算同花 [['♦5', 5], ['♣5', 5], ['♦10', 10]] 510
计算同花顺 [['♦5', 5], ['♣5', 5], ['♦10', 10]] 510
计算豹子 [['♦5', 5], ['♣5', 5], ['♦10', 10]] 510
开始计算玩家peiqi的牌
计算单牌 [['♣9', 9], ['♦Q', 12], ['♣K', 13]] 142.9
计算对子 [['♣9', 9], ['♦Q', 12], ['♣K', 13]] 142.9
计算顺子 [['♣9', 9], ['♦Q', 12], ['♣K', 13]] 142.9
计算同花 [['♣9', 9], ['♦Q', 12], ['♣K', 13]] 142.9
计算同花顺 [['♣9', 9], ['♦Q', 12], ['♣K', 13]] 142.9
计算豹子 [['♣9', 9], ['♦Q', 12], ['♣K', 13]] 142.9
开始计算玩家智哥的牌
计算单牌 [['♠6', 6], ['♦9', 9], ['♥K', 13]] 139.6
计算对子 [['♠6', 6], ['♦9', 9], ['♥K', 13]] 139.6
计算顺子 [['♠6', 6], ['♦9', 9], ['♥K', 13]] 139.6
计算同花 [['♠6', 6], ['♦9', 9], ['♥K', 13]] 139.6
计算同花顺 [['♠6', 6], ['♦9', 9], ['♥K', 13]] 139.6
计算豹子 [['♠6', 6], ['♦9', 9], ['♥K', 13]] 139.6
开始计算玩家小芸的牌
计算单牌 [['♥8', 8], ['♥10', 10], ['♠K', 13]] 140.8
计算对子 [['♥8', 8], ['♥10', 10], ['♠K', 13]] 140.8
计算顺子 [['♥8', 8], ['♥10', 10], ['♠K', 13]] 140.8
计算同花 [['♥8', 8], ['♥10', 10], ['♠K', 13]] 140.8
计算同花顺 [['♥8', 8], ['♥10', 10], ['♠K', 13]] 140.8
计算豹子 [['♥8', 8], ['♥10', 10], ['♠K', 13]] 140.8
[['old_shang', 153.5], ['alex', 510], ['peiqi', 142.9], ['智哥', 139.6], ['小芸', 140.8]]
赢家是 ['alex', 510]

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/794826.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存