基于Python的简易宿舍管理系统(课程作业附课程小论文)

本文所有基础知识可通过此链接进行训练点我开练

本次为三个月学校学习的课程作业,仅用到Python入门知识,简旦易懂。

涉及到的主要有:列表,字典,函数定义调用,循环结构等入门知识

可满足大部分学校此课的基本要求,但添加的功能较少,可在此基础上进行二创,欢迎借鉴!

话不多说,上代码!

message = []
room_number = []
room_name = []


# 欢迎界面
def welcome():
    print('欢迎使用XXXX大学学生宿舍管理系统')


# 目录
def catalogue():
    print('1.添加学生住宿信息')
    print('2.修改学生住宿信息')
    print('3.删除学生信息')
    print('4.浏览学生信息')
    print('5.查找住宿情况')
    print('6.退出系统')


# 1.添加信息功能
def add(name, classes, phone, building, room, berth):
    student = {'name': name, 'classes': classes, 'phone': phone, 'building': building, 'room': room, 'berth': berth}
    message.append(student)
    print('添加信息成功')


# 2.修改信息功能
def alter(name, new_classes, new_phone, new_building, new_room, new_berth):
    for student in message:
        if student['name'] == name:
            student['classes'] = new_classes
            student['phone'] = new_phone
            student['building'] = new_building
            student['room'] = new_room
            student['berth'] = new_berth
            print('修改信息成功')
            break


# 3.删除信息功能
def delete(name):
    for student in message:
        if student['name'] == name:
            message.remove(student)
            break


# 4.浏览学生信息
def details():
    print('name\t\tclasses\t\tphone\t\tbuilding\t\troom\t\tberth')
    for student in message:
        print("%-10s\t\t%-10s\t\t%-10s\t\t%-10s\t\t%-10s\t\t%-10s" % \
              (student['name'], student['classes'], student['phone'], \
               student['building'], student['room'], student['berth']))


# 5.查找住宿情况
def seek():
    print('*' * 15)
    print('a.按学生姓名查询')
    print('b.按宿舍号查找')
    print('c.返回')


# a.按学生姓名查询学生住宿情况
def names(na):
    for student in message:
        if student['name'] == na:
            print('name\t\tclasses\t\tphone\t\tbuilding\t\troom\t\tberth')
            print("%-10s\t\t%-10s\t\t%-10s\t\t%-10s\t\t%-10s\t\t%-10s" % \
                  (student['name'], student['classes'], student['phone'], \
                   student['building'], student['room'], student['berth']))
            break
        else:
            print('查无此人')


# b.按宿舍号查找宿舍入住情况
def buildings(roo):
    for student in message:
        if student['room'] == roo:
            print(room_name)
            break
        else:
            print("无")


def ehk():
    while True:
        welcome()
        catalogue()
        command = input('请输入你的选择:')
        if command == '6':
            print('欢迎下次光临')
            break
        elif command == '1':
            print('添加新同学')
            name = input('请输入姓名:')
            classes = input('请输入班级:')
            phone = input('请输入电话号码:')
            building = input('请输入楼号:')
            room = input('请输入宿舍号:')
            berth = input('请输入床位:')
            room_number.append(room)
            if room not in room_number:
                pass
            else:
                room_name.append(name)
            add(name, classes, phone, building, room, berth)
        elif command == '2':
            print('修改学生信息')
            name = input('请输入要修改的学生的姓名:')
            classes = input('请输入新的的班级:')
            phone = input('请输入新的电话号码:')
            building = input('请输入新的楼号:')
            room = input('请输入新的房间号:')
            berth = input('请输入新的床位:')
            alter(name, classes, phone, building, room, berth)
        elif command == '3':
            print('删除学生信息')
            name = input('请输入要删除的学生的姓名:')
            delete(name)
        elif command == '4':
            print('浏览学生信息')
            details()
        elif command == '5':
            print('查找住宿情况')
            seek()
            com = input('请输入选项:')
            if com == 'a':
                print('按学生姓名查询')
                na = input('请输入学生姓名:')
                names(na)
            elif com == 'b':
                print('按宿舍号查找')
                roo = input('请输入宿舍号:')
                buildings(roo)
            elif com == 'c':
                continue
            else:
                pass
        else:
            pass


# 定义列表,用来记录用户名和密码:
users = ['张三', '李四']
passwd = ['zhangsan', 'lisi']

while True:
    count = 0
    if count < 3:
        user = input("用户名:")
        mima = input("密码:")
        count += 1
        if user in users:
            index = users.index(user)
            pass_wd = passwd[index]
            if mima == pass_wd:
                print("%s登录成功" % user)
                ehk()
                break
            else:
                print("%s登录失败" % user)
        else:
            print("%s用户不存在" % user)
    else:
        print("已经超过三次机会")
        break

此系统仍有很多不足,如制表未对齐,功能少,不可存储多次班级宿舍信息进行归类等,有精力将进行修改完善。对此系统有任何疑问也可私聊询问。

此外暑假将分享网络爬虫的学习分享,并会写几篇简单实战项目,欢迎小白关注一起学习。目前还做了算法学习初步打算(Python方向),有兴趣可以交流互相监督学习。

另附课程小论文,在资源中可以免费下载

你可能感兴趣的:(项目作业,python,开发语言,pycharm)