Python——简单的学生信息管理系统

    一个简单的学生信息管理系统

id_list = []
name_list = []
sex_list = []
#查询学生信息函数
def check_student():
    #列表的查找方式
    id_check = input("请输入要查询的学生学号")
    id_check_index = id_list.index(id_check)#找到学号列表的下标,对应找到该学生信息
    print("\n")
    print("学生学号:",id_list[id_check_index],"\n学生姓名:",name_list[id_check_index],"\n学生性别:",sex_list[id_check_index])
    """
    # 文件查找方式
    #id_input = input("请输入要查询的学生学号")
    f = open("student_name.txt")
    id_check = f.read()
    print(id_check)
    f.close()
    """

#添加学生信息函数
def add_student():
    print("###########'s'键停止输入#############")
    while True:

        name = input("输入学生姓名:\n")
        id_card = input("输入学生学号:\n")
        sex = input("输入学生性别:\n")

        id_list.append(id_card)
        name_list.append(name)
        sex_list.append(sex)

        """
        f = open("student_name.txt", "a")
        f.write(id_card+" "+sex+" "+name+" "+"\n")
        f.close()
        """
        # 退出输入信息的循环
        stop = input("")# 循环输入学生信息2
        if stop == 's':
            break

def delete_student():
    id_delete = input("请输入要删除的学生学号")
    id_delete_index = id_list.index(id_delete)#找到学号列表的下标,对应找到该学生信息
    print("\n")
    choice_delete = input("是否删除,是请选择1\n")
    if choice_delete == '1':
        del id_list[id_delete_index]
        del name_list[id_delete_index]
        del sex_list[id_delete_index]

        print("学号为",id_delete,"的同学的信息已删除!")
    else:
        print("请选择别的功能")


#主函数
print("************欢迎来到学生成绩管理系统**************")
while True:
    print("\n")
    print("         1、查询学生成绩           2、添加学生成绩")
    print("         3、删除学生成绩           4、退出学生系统")
    print("\n")
    choice = input("选择对应功能的数字:")
    if choice == "1":
        check_student()
    if choice == "2":
        add_student()
    if choice == '3':
        delete_student()
    if choice == '4':
        break
    print("\n")

print("************感谢使用学生成绩管理系统**************")
在这里,只是把学生信息存储在了列表中,想要在文件里进行增删改查,但是没有成功,希望大家可以帮忙改一下 大哭

猜你喜欢

转载自blog.csdn.net/qq_40368659/article/details/80385898