马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 669021067 于 2021-8-4 15:10 编辑
题目
1. 程序启动后,给用户提供查询接口;,允许用户重复查股票行情信息(用到循环)
2. 允许用户通过模糊查询股票名,比如;如输;“啤酒”, 就把所有股票名称中包含“啤酒”的信息打印出来
3. 允许按股票价格、涨跌幅、换手率这几列来筛选信息,比如输入“价格>50”则把价格大;于50的股票
都打印,输入“市盈率<50“,则把市盈率大于50的股票都打印,不用判断等于。
股票代码,股票名称,当前价,涨跌额,涨跌幅,年初⾄今,成交量,成交额,换⼿率,市盈率(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亿
SZ300279,和晶科技,5.49,+0.29,+5.58%,-8.50%,2328.20万,1.31亿,5.33%,亏 损,0.00%,24.65亿
import re
accounts={#建一个空字典
}
f=open("stock_data.txt",encoding='utf-8')
name=f.readline().strip().strip()#f.readline把字典第一行读出后面就不会打印了
#print(name)
for line in f:
line =line.strip().split(',')
accounts[line[0]]=line
for i,j in accounts.items():#这个代码是让字典一行一行打印
print(i,j)
while True:
cmd =input("输入要查的股票指令:").strip()
if not cmd:#如果用户输入指令不存在就重新输入
continue
for acc_key ,acc_ver in accounts.items():
a_names = acc_ver[1]
if cmd in a_names:#判断用户输入的指令在不在a_names里
print(acc_ver)#在的话就直接打印出value
#允许按**当前价,涨跌幅,换手率**这几列来筛选信息
#判断公式合法性(正则表达式)
cmd_2=re.split("[><]",cmd)
if len(cmd_2) != 2:
continue
filter_key,filter_val = cmd_2
#列名是否合法
if filter_key not in["当前价","涨跌幅","换手率"]:
continue
#数值的合法性
try:#只要写了try,python解释器就会认为下面那行代码是有可能报错的
filter_val =float(filter_val)
except ValueError:#如果报错不要停止显示出红色的东西,直接执行excpet后面的continue重新输入
continue
bba = name.index(filter_key)
for acc_key,acc_ver in accounts.items():
if ">" in cmd:
if float(acc_ver[bba].strip("%")) > filter_val:
print(acc_ver)
else:
if float(acc_ver[bba].strip("%")) < filter_val:
print(acc_ver)
|