欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python写酒店管理系统报告_酒店管理系统学生工作-部门管理Python,作品,python

发布时间:2024/3/24 python 59 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python写酒店管理系统报告_酒店管理系统学生工作-部门管理Python,作品,python 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

# Author: cybersnow

# 开发时间:2020-17-07

# 开发工具:PyCharm

import re # 导入正则表达式模块

import os # 导入操作系统模块

database_filename = "cyberwinhotel.txt" # 部门信息保存文件

def menu():

# 输出菜单

print('''

---------------酒店息管理系统------------

==================功能菜单================

1 录入部门信息

2 查找部门信息

3 删除部门信息

4 修改部门信息

5 排序

6 统计部门总数

7 显示所有部门信息

0 退出系统

=======================================

说明:通过数字选择菜单

=======================================

''')

def main():

ctrl = True # 标记是否退出系统

while (ctrl):

menu() # 显示菜单

option = input("请选择:") # 选择菜单项

option_str = re.sub("\D", "", option) # 提取数字

if option_str in ['0', '1', '2', '3', '4', '5', '6', '7']:

option_int = int(option_str)

if option_int == 0: # 退出系统

print('您已退出酒店管理系统!')

ctrl = False

elif option_int == 1: # 录入酒店成绩信息

insert()

elif option_int == 2: # 查找酒店成绩信息

search()

elif option_int == 3: # 删除酒店成绩信息

delete()

elif option_int == 4: # 修改酒店成绩信息

modify()

elif option_int == 5: # 排序

sort()

elif option_int == 6: # 统计酒店总数

total()

elif option_int == 7: # 显示所有酒店信息

show()

'''录入酒店信息'''

def insert():

depList = [] # 保存酒店信息的列表

mark = True # 是否继续添加

while mark:

id = input("请输入部门ID(如1):")

if not id:

break

dep_name = input("请输入部门名称:")

if not dep_name:

break

# 将输入的几点信息保存到字典

deptone = {"id": id, "dep_name": dep_name}

depList.append(deptone) # 将部门字典添加到列表中

inputList = input("是否继续添加?(y/n):")

if inputList == 'y': # 继续添加

mark = True

else:

mark = False

save(depList) # 将部门信息保存到文件

print("部门信息录入完毕!!!")

'''将部门信息保存到文件'''

def save(depList):

try:

deptlist_txt = open(database_filename, 'a') # 以追加模式打开

except Exception as e:

deptlist_txt = open(database_filename, 'w') # 文件不存在,创建文件并打开

for info in depList:

deptlist_txt.write(str(info) + "\n") # 执行存储,添加换行符

deptlist_txt.close() # 关闭文件

'''查询部门信息'''

def search():

mark = True

dept_query = []

while mark:

id = ""

dep_name = ""

if os.path.exists(database_filename):

mode = input("按ID查询输入1:按名称查询输入2:")

if mode == "1":

id = input("请输入部门ID:")

elif mode == "2":

dep_name = input("请输入部门名称:")

else:

print("您输入有误,请重新输入!")

search()

with open(database_filename, "r") as file:

deplistr = file.readlines()

for list in deplistr:

d = dict(eval(list))

if id is not "":

if d['id'] == id:

dept_query.append(d)

elif dep_name is not "":

if d['dep_name'] == dep_name:

dept_query.append(d)

show_dept(dept_query)

dept_query.clear()

inputMark = input("是否继续查询?(y/n):")

if inputMark == "y":

mark = True

else:

mark = False

else:

print("暂未保存数据信息...")

return

'''将保存在列表中的部门信息显示出来'''

def show_dept(depList):

if not depList:

print("无效的数据")

return

format_title = "{:^6}{:^12}\t"#\t{:^8}\t{:^10}\t{:^10}\t{:10}"

print(format_title.format("ID", "部门名称"))

format_data = "{:^6}{:^12}\t"#"{:^10}\t{:^10}\t{:^10}\t{:10}"

print("部门信息开始")

for info in depList:

{

print(format_data.format(info.get("id"), info.get("dep_name"))),

print("部门信息结束")

}

'''删除部门信息'''

def delete():

mark = True # 标记是否循环

while mark:

depttId = input("请输入要删除的部门ID:")

if depttId is not "": # 判断要删除的部门ID是否存在

if os.path.exists(database_filename):

with open(database_filename, 'r') as rfile:

deptlist_old = rfile.readlines()

else:

deptlist_old = []

ifdel = False # 标记是否删除

if deptlist_old: # 如果存在部门信息

with open(database_filename, 'w') as wfile:

d = {} # 定义空字典

for list in deptlist_old:

d = dict(eval(list)) # 字符串转字典

if d['id'] != depttId:

wfile.write(str(d) + "\n") # 将一条信息写入文件

else:

ifdel = True # 标记已经删除

if ifdel:

print("ID为%s的部门信息已经被删除..." % depttId)

else:

print("没有找到ID为%s的部门信息..." % depttId)

else:

print("不存在部门信息")

break

show() # 显示全部部门信息

inputMark = input("是否继续删除?(y/n):")

if inputMark == "y":

mark = True # 继续删除

else:

mark = False # 退出删除部门信息操作

'''修改部门信息'''

def modify():

show() # 显示全部部门信息

if os.path.exists(database_filename):

with open(database_filename, 'r') as rfile:

deptlist_old = rfile.readlines()

else:

return

depttId = input("请输入要修改的部门ID:")

with open(database_filename, 'w') as wfile:

for deptone in deptlist_old:

d = dict(eval(deptone))

if d['id'] == depttId:

print("找到了这个部门,可以修改他的信息")

while True: # 输入要修改的信息

try:

d["name"] = input("请输入部门名称:")

except:

print("您输入有误,请重新输入!")

else:

break

deptone = str(d) # 将字典转为字符串

wfile.write(deptone + "\n") # 将修改信息写入到文件

print("修改成功")

else:

wfile.write(deptone) # 将未修改的信息写入文件

mark = input("是否继续修改其他部门信息?(y/n):")

if mark == "y":

modify()

'''排序'''

def sort():

show()

if os.path.exists(database_filename):

with open(database_filename, 'r') as file:

deptlist_old = file.readlines()

deptlist_new = []

for list in deptlist_old:

d = dict(eval(list))

deptlist_new.append(d)

else:

return

ascORdesc = input("请选择(0升序;1降序)")

if ascORdesc == "0":

ascORdescBool = False # 标记变量,为False时表示升序,为True时表示降序

elif ascORdesc == "1":

ascORdescBool = True

else:

print("您输入的信息有误,请重新输入!")

sort()

mode = input("请选择排序方式(1):")

if mode == "1": # 按英语成绩排序

deptlist_new.sort(key=lambda x: x["id"], reverse=ascORdescBool)

else:

print("您的输入有误,请重新输入!")

sort()

show_dept(deptlist_new) # 显示排序结果

'''统计部门总数'''

def total():

if os.path.exists(database_filename):

with open(database_filename, 'r') as rfile:

dept_old = rfile.readlines()

if dept_old:

{

print("部门统计"),

print("一共有%d个部门!" % len(dept_old)),

print("--"),

}

else:

print("还没有录入部门信息")

else:

print("暂未保存数据信息")

'''显示所有部门信息'''

def show():

dept_new = []

if os.path.exists(database_filename):

with open(database_filename, 'r') as rfile:

deptlist_old = rfile.readlines()

for list in deptlist_old:

dept_new.append(eval(list))

if dept_new:

show_dept(dept_new)

else:

print("暂未保存数据信息")

if __name__ == '__main__':

main()

总结

以上是生活随笔为你收集整理的python写酒店管理系统报告_酒店管理系统学生工作-部门管理Python,作品,python的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。