員工資訊表 資訊檢索
阿新 • • 發佈:2020-07-30
import sys
def get_register():
li_info=[]
with open('register',encoding='utf-8',mode="r") as f:
for i in f:
li_personal = {}
li_personal["id"]=i.strip().split(',')[0]
li_personal["name"] = i.strip().split(',')[1]
li_personal["age"] = i.strip().split(',')[2]li_personal["phone"] = i.strip().split(',')[3]
li_personal["job"] = i.strip().split(',')[4]
li_info.append(li_personal)
del li_info[0]
return li_info
li_info=get_register()
print(li_info)
s=input('輸入查詢欄位').strip()
key_in=s.split(' ')
select_content_li=[]
judge_content_li=[]stop=key_in.index('where')
for i in range(1,stop):
select_content_li.append(key_in[i])
for i in range(stop+1,len(key_in)):
judge_content_li.append(key_in[i])
print(select_content_li)
print(judge_content_li)
judge=judge_content_li[0]
symbol=judge_content_li[1]
requirement=judge_content_li[2]
def aim():
if symbol=='>':goal_list= filter(lambda X:X[judge_content_li[0]]>requirement,li_info)
return list(goal_list)
elif symbol=='<':
goal_list = filter(lambda X: X[judge_content_li[0]] < requirement, li_info)
return list(goal_list)
elif symbol=='=':
goal_list = filter(lambda X: X[judge_content_li[0]] == requirement, li_info)
return list(goal_list)
elif symbol=='like':
goal_list1=[]
for i in li_info:
if requirement in i[judge]:
goal_list1.append(i)
return goal_list1
ret=aim()
if ret==[]:
print("無匹配結果")
else:
for i in select_content_li:
print(ret[0][i])