程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

python3 简陋的学生信息管理系统

发布于2019-08-05 11:08     阅读(1014)     评论(0)     点赞(4)     收藏(1)


# 编写一个“学生信息管理系统”
# 输入序号:1. 输入学生信息,学生信息包括:id,name,age,gender(用什么数据类型保存?)
# 2. 查询:输入学生姓名和id,显示学生个人信息
# 3. 修改:输入学生姓名或者id,可以对学生信息进行修改
# 4. 删除:输入学生姓名或者id,删除对应学生信息

代码如下:::
def increase():
    student = [input("学号:"), input("姓名:"), input("年龄:"), input("性别:")]
    students.append(student)

def query():
    s = input("输入学生学号或姓名:")
    if s.isdigit() == True:
        id = s
        # enumerate()是python的内置函数、适用于python2.x和python3.x
        # enumerate在字典上是枚举、列举的意思
        # enumerate参数为可遍历/可迭代的对象(如列表、字符串)
        # enumerate多用于在for循环中得到计数,利用它可以同时获得索引和值,即需要index和value值的时候可以使用enumerate
        for station, item in enumerate(students):
            if id in item:
                print("此学生信息为:", item)
                break
            if station + 1 == len(students):
                print("查无此人")
    else:
        name = s
        for station, item in enumerate(students):
            if name in item:
                print("此学生信息为:", item)
                break
            if station + 1 == len(students):
                print("查无此人")

def modify():
    s = input("输入学生学号或姓名:")
    if s.isdigit() == True:
        id = s
        for item in students:
            if id in item:
                print(item)
                while 1:
                    print("--选择修改具体信息--")
                    n = int(input("请输入要进行的操作序号:1.学号 2.姓名 3.年龄 4.性别"))
                    if n == 1:
                        item[0] = input("输入修改后的学号:")
                    elif n == 2:
                        item[1] = input("输入修改后的姓名:")
                    elif n == 3:
                        item[2] = input("输入修改后的年龄:")
                    else:
                        item[3] = input("输入修改后的性别:")
                    print("--修改完成--")
                    break
    else:
        name = s
        for item in students:
            if name in item:
                print(item)
                while 1:
                    print("--选择修改具体信息--")
                    n = int(input("请输入要进行的操作序号:1.学号 2.姓名 3.年龄 4.性别"))
                    if n == 1:
                        item[0] = input("输入修改后的学号:")
                    elif n == 2:
                        item[1] = input("输入修改后的姓名:")
                    elif n == 3:
                        item[2] = input("输入修改后的年龄:")
                    else:
                        item[3] = input("输入修改后的性别:")
                    print("--修改完成--")
                    break
def remove():
    s = input("输入学生学号或姓名:")
    if s.isdigit() == True:
        id = s
        for item in students:
            if id in item:
                i = students.index(item)
                del(students[i])
    else:
        name = s
        for item in students:
            if name in item:
                i = students.index(item)
                del(students[i])


if __name__ == '__main__':

    students = [["1", "王二麻子", "15", ""], ["2", "张三", "16", ""]]
    while 1:
        print("-----------------------进入主界面--------------------------")
        print("---------------1.增加 2.查询 3.修改 4.删除-----------------")
        n = int(input("请输入:"))
        if n == 1:
            increase()  #调用增加函数
        elif n == 2:
            query()  #调用查询函数
        elif n == 3:
            modify()  #调用修改函数
        else:
            remove()  #调用删除函数
        print(students)
        print("-----------------------------------------------------------")

运行结果如下:

-----------------------进入主界面--------------------------
---------------1.增加 2.查询 3.修改 4.删除-----------------
请输入:1
学号:3
姓名:李四
年龄:17
性别:男
[['1', '王二麻子', '15', ''], ['2', '张三', '16', ''], ['3', '李四', '17', '']]
-----------------------------------------------------------
-----------------------进入主界面--------------------------
---------------1.增加 2.查询 3.修改 4.删除-----------------
请输入:2
输入学生学号或姓名:2
此学生信息为: ['2', '张三', '16', '']
[['1', '王二麻子', '15', ''], ['2', '张三', '16', ''], ['3', '李四', '17', '']]
-----------------------------------------------------------
-----------------------进入主界面--------------------------
---------------1.增加 2.查询 3.修改 4.删除-----------------
请输入:3
输入学生学号或姓名:3
['3', '李四', '17', '']
--选择修改具体信息--
请输入要进行的操作序号:1.学号 2.姓名 3.年龄 4.性别2
输入修改后的姓名:周五
--修改完成--
[['1', '王二麻子', '15', ''], ['2', '张三', '16', ''], ['3', '周五', '17', '']]
-----------------------------------------------------------
-----------------------进入主界面--------------------------
---------------1.增加 2.查询 3.修改 4.删除-----------------
请输入:4
输入学生学号或姓名:3
[['1', '王二麻子', '15', ''], ['2', '张三', '16', '']]
-----------------------------------------------------------

还有许多可以优化的地方,等我继续学习一下哈哈



所属网站分类: 技术文章 > 博客

作者:喵喵喵

链接:https://www.pythonheidong.com/blog/article/4215/0a6711d54d8c3c145290/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

4 0
收藏该文
已收藏

评论内容:(最多支持255个字符)