員工資訊表作業

2022-07-26 16:57:11 字數 4501 閱讀 8947

dic = 

defadd_info(filename):

user_info =

with open(filename, 'r

', encoding='

utf-8

') as f:

lines =f.readlines()

last_line = lines[-1]

id_max = last_line[dic['id'

]]

ifid_max.isdigit():

name = input('

請輸入姓名:

').strip()

ifname.isspace():

print('

姓名不能為空')

else

: age = input('

請輸入年齡:

').strip()

ifage.isspace():

print('

年齡不能為空')

elif

notage.isdigit():

print('

年齡必須是數字')

else

: phone = input('

').strip()

ifphone.isspace():

print('

**不能為空')

elif

notphone.isdigit():

print('

**必須全部由數字組成')

else

: job = input('

請輸入工作:

').strip()

ifjob.isspace():

print('

工作不能為空')

else

: with open(filename, 'a

', encoding='

utf-8

') as f:

info = ','

.join(user_info)

iff.writable():

if f.write(info) >0:

print('

使用者[%s]的資訊新增成功!

'%name)

defdel_info():

pass

defread_file(filename):

with open(filename, encoding='

utf-8

') as f:

for line in

f: line =line.strip()

line_list = line.split(','

)

yield

line_list

defcond_filter(condition, filename):

condition =condition.strip()

if'>='in

condition:

condition = condition.split('

>=')

col =condition[0].strip()

val = condition[1].strip()

g =read_file(filename)

for line_list in

g:

if int(line_list[dic[col]]) >=int(val):

yield

line_list

elif

'<='in

condition:

condition = condition.split('

<=')

col =condition[0].strip()

val = condition[1].strip()

g =read_file(filename)

for line_list in

g:

if int(line_list[dic[col]]) <=int(val):

yield

line_list

elif

'>'in

condition:

condition = condition.split('

>')

col =condition[0].strip()

val = condition[1].strip()

g =read_file(filename)

for line_list in

g:

if int(line_list[dic[col]]) >int(val):

yield

line_list

elif

'<'in

condition:

condition = condition.split('

<')

col =condition[0].strip()

val = condition[1].strip()

g =read_file(filename)

for line_list in

g:

if int(line_list[dic[col]]) yield

line_list

elif

'like'in

condition:

condition = condition.split('

like')

col =condition[0].strip()

val = condition[1].strip()

g =read_file(filename)

for line_list in

g:

if val in

line_list[dic[col]]:

yield

line_list

else

:

print('

查詢暫時只支援》=、<=、>、<、like')

defprint_info(col_lst, staff):

if'*'

incol_lst:

col_lst =dic.keys()

for i in

col_lst:

print(i, end='

\t\t\t')

print(''

)

for staff_info in

staff:

for i in

col_lst:

print(staff_info[dic[i.strip()]], end='

\t\t\t')

print(''

)print("

請選擇你的功能:新增使用者資訊 刪除使用者資訊 查詢使用者資訊 [exit] 退出")

choose = input("

請選擇你的功能:

").strip()

while

true:

ret = input("

>>>

").lower()

if'exit

'.lower() ==ret.strip():

break

if choose == '3'

: if'

where'in

ret:

select, where = ret.split('

where')

select, table = select.split('

from')

cols = select.replace('

select

', ''

).strip()

cols = cols.split(','

) g =cond_filter(where.strip(), table.strip())

print_info(cols, g)

else

: select, table = ret.split('

from')

cols = select.replace('

select

', ''

).strip()

cols = cols.split(','

) g =read_file(table.strip())

print_info(cols, g)

ret = input("

>>>")

elif choose == '1'

: add_info(

'userinfo')

ret = input("

>>>

")

員工資訊表作業

檔案儲存格式如下 id,name,age,phone,job 1,alex,22,13651054608,it 2,egon,23,13304320533,tearcher 3,nezha,25,1333235322,it 現在需要對這個員工資訊檔案進行增刪改查。基礎必做 a.可以進行查詢,支援三種...

員工資訊表

有以下員工資訊表 staff id name agephone dept enroll date 1alex li 2213651054608 it2013 04 01 2jack wang 3013304320533 hr2015 05 03 3rain liu 251383235322 sale...

新員工錄入員工資訊表

公司將100名員工的資訊以鍊錶的形式儲存起來,並以工齡將其排序,構成順序表,先從公司其他部門轉來乙個員工,編寫程式,將新加入的員工資訊錄入表中 本題實現了在順序鍊錶中插入節點,通過對比各節點資料域的關係確定插入點的位置,然後對應插入點位置確定資料域關鍵字段 include include struc...