日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python课题设计职工信息管理系统_用Python实现职工信息管理系统

發(fā)布時間:2023/12/15 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python课题设计职工信息管理系统_用Python实现职工信息管理系统 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

想要實現(xiàn)一個職工管理系統(tǒng)

首先我們看一下想要實現(xiàn)什么功能

最基礎(chǔ)的增刪改查肯定要實現(xiàn)的

然后增加一下數(shù)據(jù)顯示、數(shù)據(jù)排序、數(shù)據(jù)統(tǒng)計功能

下面直接上代碼

增加職工數(shù)據(jù)

# 接收用戶收入

id = input("請輸入職工號")

name = input("請輸入姓名")

sex = input("請輸入性別")

age = input("請輸入年齡")

education = input("請輸入學(xué)歷")

address = input("請輸入住址")

photonumber = input("請輸入電話")

money = input("請輸入工資")

# 向列表中添加數(shù)據(jù)

data.append([id, name, sex, age, education, address, photonumber, money])

print("添加成功")

# 調(diào)用保存函數(shù) 保存數(shù)據(jù)

save()

刪除職工數(shù)據(jù)

id = input("請輸入你要修改的職工編號")

ids = [i[0] for i in data]

if id not in ids:

print("您查詢的職工不存在")

return

else:

del data[ids.index(id)]

print("刪除成功")

save()

查詢職工數(shù)據(jù)

# 選擇查詢目標(biāo)

flag = int(input("1.按照職工編號查詢 2.按照職工姓名查詢"))

if flag == 1:

id = input("輸入職工編號")

# 職工編號列表

ids = [i[0] for i in data]

# 判斷輸入的編號是否存在

if id not in ids:

print("您查詢的職工不存在")

return

else:

print("職工號 姓名 性別 年齡 學(xué)歷 住址 電話 工資")

# 打印該編號的信息

for i in data[ids.index(id)]:

print(i, end=" ")

print()

else:

name = input("輸入職工姓名")

# 職工姓名列表

names = [i[1] for i in data]

# 判斷輸入的姓名是否存在

if name not in names:

print("您查詢的職工不存在")

return

else:

print("職工號 姓名 性別 年齡 學(xué)歷 住址 電話 工資")

# 同上

for i in data[names.index(name)]:

print(i, end=" ")

print()

修改職工信息

id = input("請輸入你要修改的職工編號")

ids = [i[0] for i in data]

if id not in ids:

print("您查詢的職工不存在")

return

else:

# 輸入要修改的數(shù)據(jù)

name = input("請輸入姓名")

sex = input("請輸入性別")

age = input("請輸入年齡")

education = input("請輸入學(xué)歷")

address = input("請輸入住址")

photonumber = input("請輸入電話")

money = input("請輸入工資")

# 修改數(shù)據(jù)

data[ids.index(id)] = [id, name, sex, age, education, address, photonumber, money]

print("修改成功")

save()

排序函數(shù)

global data

data = sorted(data, key=lambda x: x[1])

統(tǒng)計函數(shù)

counts = {}

# 統(tǒng)計每個工資的人數(shù)

for i in data:

counts[int(i[-1])] = counts.get(i[-1], 0) + 1

# 按照人數(shù)多少排序

counts = dict(sorted(counts.items(), key=lambda x: x[1], reverse=True))

# 將結(jié)果打印

for money, count in counts.items():

print("{0:<10}{1:>5}".format(money, count))

print("工資最多的是:", max(counts))

print("工資最少的是:", min(counts))

顯示函數(shù)

# 打印標(biāo)題

print("職工號 姓名 性別 年齡 學(xué)歷 住址 電話 工資")

# 遍歷數(shù)據(jù)列表 然后打印數(shù)據(jù)

for i in data:

for j in i:

print(j, end=" ")

print()

讀取保存函數(shù)

def save(): # 保存函數(shù)

# 打開文件,寫入數(shù)據(jù)

with open("數(shù)據(jù).csv","w") as j:

for i in data:

j.write(",".join(i)+"

")

j.close()

def load(): # 讀取函數(shù)

# 讀取文件

with open("數(shù)據(jù).csv","r") as j:

# 讀取每行數(shù)據(jù)

for i in j.readlines():

# 清洗掉換行符 然后以逗號為間隔符分割

data.append(i.replace("

","").split(","))

j.close()

總結(jié)整體代碼:

def add(): # 添加數(shù)據(jù)函數(shù)

# 接收用戶收入

id = input("請輸入職工號")

name = input("請輸入姓名")

sex = input("請輸入性別")

age = input("請輸入年齡")

education = input("請輸入學(xué)歷")

address = input("請輸入住址")

photonumber = input("請輸入電話")

money = input("請輸入工資")

# 向列表中添加數(shù)據(jù)

data.append([id, name, sex, age, education, address, photonumber, money])

print("添加成功")

# 調(diào)用保存函數(shù) 保存數(shù)據(jù)

save()

def show(): # 顯示函數(shù)

# 打印標(biāo)題

print("職工號 姓名 性別 年齡 學(xué)歷 住址 電話 工資")

# 遍歷數(shù)據(jù)列表 然后打印數(shù)據(jù)

for i in data:

for j in i:

print(j, end=" ")

print()

def quety(): # 查詢函數(shù)

# 選擇查詢目標(biāo)

flag = int(input("1.按照職工編號查詢 2.按照職工姓名查詢"))

if flag == 1:

id = input("輸入職工編號")

# 職工編號列表

ids = [i[0] for i in data]

# 判斷輸入的編號是否存在

if id not in ids:

print("您查詢的職工不存在")

return

else:

print("職工號 姓名 性別 年齡 學(xué)歷 住址 電話 工資")

# 打印該編號的信息

for i in data[ids.index(id)]:

print(i, end=" ")

print()

else:

name = input("輸入職工姓名")

# 職工姓名列表

names = [i[1] for i in data]

# 判斷輸入的姓名是否存在

if name not in names:

print("您查詢的職工不存在")

return

else:

print("職工號 姓名 性別 年齡 學(xué)歷 住址 電話 工資")

# 同上

for i in data[names.index(name)]:

print(i, end=" ")

print()

def modify(): # 修改函數(shù)

# 原理同上

id = input("請輸入你要修改的職工編號")

ids = [i[0] for i in data]

if id not in ids:

print("您查詢的職工不存在")

return

else:

# 輸入要修改的數(shù)據(jù)

name = input("請輸入姓名")

sex = input("請輸入性別")

age = input("請輸入年齡")

education = input("請輸入學(xué)歷")

address = input("請輸入住址")

photonumber = input("請輸入電話")

money = input("請輸入工資")

# 修改數(shù)據(jù)

data[ids.index(id)] = [id, name, sex, age, education, address, photonumber, money]

print("修改成功")

save()

def sort(): # 排序函數(shù)

global data

data = sorted(data, key=lambda x: x[1])

def statistics(): # 統(tǒng)計函數(shù)

counts = {}

# 統(tǒng)計每個工資的人數(shù)

for i in data:

counts[int(i[-1])] = counts.get(i[-1], 0) + 1

# 按照人數(shù)多少排序

counts = dict(sorted(counts.items(), key=lambda x: x[1], reverse=True))

# 將結(jié)果打印

for money, count in counts.items():

print("{0:<10}{1:>5}".format(money, count))

print("工資最多的是:", max(counts))

print("工資最少的是:", min(counts))

def delete(): # 刪除函數(shù)

# 原理同上

id = input("請輸入你要修改的職工編號")

ids = [i[0] for i in data]

if id not in ids:

print("您查詢的職工不存在")

return

else:

del data[ids.index(id)]

print("刪除成功")

save()

def save(): # 保存函數(shù)

# 打開文件,寫入數(shù)據(jù)

with open("數(shù)據(jù).csv","w") as j:

for i in data:

j.write(",".join(i)+"

")

j.close()

def load(): # 讀取函數(shù)

# 讀取文件

with open("數(shù)據(jù).csv","r") as j:

# 讀取每行數(shù)據(jù)

for i in j.readlines():

# 清洗掉換行符 然后以逗號為間隔符分割

data.append(i.replace("

","").split(","))

j.close()

if __name__ == "__main__":

data = [] # 數(shù)據(jù)保存列表

# 讀取文件 如果文件不存在 報錯跳過 無視

try:

load()

except FileNotFoundError:

pass

while True:

# 根據(jù)玩家的輸入 選擇相應(yīng)的功能

choice = int(input("1.添加職工數(shù)據(jù)

2.顯示職工數(shù)據(jù)

3.查詢職工數(shù)據(jù)

4.修改職工數(shù)據(jù)

5.刪除職工數(shù)據(jù)

6.保存職工數(shù)據(jù)

7.排序職工數(shù)據(jù)

8.統(tǒng)計職工工資數(shù)據(jù)

9.退出"))

if choice == 1:

add()

elif choice == 2:

show()

elif choice == 3:

quety()

elif choice == 4:

modify()

elif choice == 5:

delete()

elif choice == 6:

save()

elif choice == 7:

sort()

elif choice == 8:

statistics()

elif choice == 9:

print("退出程序")

break

到此這篇關(guān)于用Python實現(xiàn)職工信息管理系統(tǒng)的文章就介紹到這了,更多相關(guān)Python 職工信息管理系統(tǒng)內(nèi)容請搜索云海天教程以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持云海天教程!

總結(jié)

以上是生活随笔為你收集整理的python课题设计职工信息管理系统_用Python实现职工信息管理系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。