コード例 #1
0
def delete_student():
    print('1.按姓名删除学生')
    print('2.按学号删除学生')
    system_info = get_system_info()
    all_students = get_system_info().get(key_all_students,[])
    if not all_students:
        print('目前还没有学生!')
        return
    value = input('请选择(1-2):')
    if value == '1':
        name = input('请输入你要删除学生的姓名:')
        for stu in all_students[:]:
            if stu[key_name] == name:
                all_students.remove(stu)
                print('该学生已删除')
                break
        system_info[key_all_students] = all_students
        file_manager.write_json_file(user_name+'.json',system_info)
    elif value == '2':
        id = input('请输入你要删除学生的学号:')
        for stu in all_students[:]:
            if stu[key_id] == id:
                all_students.remove(stu)
                print('该学生已删除')
                break
        system_info[key_all_students] = all_students
        file_manager.write_json_file(user_name+'.json',system_info)
コード例 #2
0
def revise_student():
    print('1.按姓名修改学生')
    print('2.按学号修改学生')
    system_info = get_system_info()
    all_students = get_system_info().get(key_all_students, [])
    if not all_students:
        print('目前还没有学生!')
        return
    value = input('请选择(1-2):')
    if value == '1':
        name = input('请输入你要修改学生的姓名:')
        for stu in all_students[:]:
            if stu[key_name] == name:
                age = input('年龄:')
                tel = input('电话:')
                stu[key_age] = age
                stu[key_tel] = tel
                print('修改学生信息成功')
        system_info[key_all_students] = all_students
        file_manager.write_json_file(user_name + '.json', system_info)
    if value == '2':
        id = input('请输入你要修改学生的学号:')
        for stu in all_students[:]:
            if stu[key_id] == id:
                name = input('名字:')
                age = input('年龄:')
                tel = input('电话:')
                stu[key_name] = name
                stu[key_age] = age
                stu[key_tel] = tel
                print('修改学生信息成功')
        system_info[key_all_students] = all_students
        file_manager.write_json_file(user_name + '.json', system_info)
コード例 #3
0
ファイル: student_system.py プロジェクト: M0use7/python
def alter_student():
    print('1.根据姓名修改学生')
    print('2.根据学号修改学生')
    value = input('请选择(1-2):')

    # 获取所有学生
    system_info = get_system_info()
    all_students = system_info.get(key_all_students,[])

    if value == '1':
        name = input('请输入需修改学生姓名:')
        for stu in all_students:
            if stu[key_name] == name:
                stu[key_tel] = input('请输入新的电话号码:')
                print('修改成功!')
    elif value == '2':
        id = input('请输入需修改学生学号:')
        for stu in all_students:
            if stu[key_id] == id:
                stu[key_tel] = input('请输入新的电话号码:')
                print('修改成功!')
    else:
        print('输入错误,请重新输入!')
    # 保存学生信息到文件中
    system_info[key_all_students] = all_students
    file_manager.write_json_file(user_name+'.json',system_info)
コード例 #4
0
ファイル: student_system.py プロジェクト: M0use7/python
def del_student():
    print('1.删除所有学生')
    print('2.根据姓名删除学生')
    print('3.根据学号删除学生')
    value = input('请选择(1-3):')
    # 获取所有学生
    system_info = get_system_info()
    all_students = system_info[key_all_students]
    if not all_students:
        print('目前还没有学生!')
        return

    if value == '1':
        sure = input('您确认要删除所有学生?(YES/NO)')
        if sure == 'YES':
            all_students.clear()
            print('删除成功!')

    elif value == '2':
        name = input('请输入删除学生姓名:')
        for stu in all_students:
            if stu[key_name] == name:
                all_students.remove(stu)
                print('删除成功!')

    elif value == '3':
        id = input('请输入删除学生学号:')
        for stu in all_students:
            if stu[key_id] == id:
                all_students.remove(stu)
                print('删除成功!')

    # 保存学生信息到文件中
    system_info[key_all_students] = all_students
    file_manager.write_json_file(user_name+'.json',system_info)
コード例 #5
0
def add_student():
    while  True:

        # 1.输入信息
        name = input('姓名:')
        age = input('年龄:')
        tel = input('电话:')
        # 2.产生id
        id, number = creat_id()

        # 3.创建学生
        stu = {key_name: name, key_age: age, key_tel: tel, key_id: id}

        # 4.保存学生信息
        system_info = get_system_info()
        all_student = system_info.get(key_all_students,[])
        all_student.append(stu)
        # 5.保存到文件中
        system_info[key_all_students] = all_student
        system_info[key_number] = number
        re = file_manager.write_json_file(user_name + '.json', system_info)
        if re:
            print('添加成功!')
        else:
            print('添加失败')

        print('1.继续添加')
        print('2.返回')
        value = input('请选择(1/2):')
        if value == '1':
            continue
        else:
            break
コード例 #6
0
ファイル: mian.py プロジェクト: M0use7/python
def register():
    # 输入用户名
    while True:
        user_name = input('请输入用户名(3-10位):')
        if not 3 <= len(user_name) <= 10:
            print('输入有误,请重新输入!')
            continue
        # 判断是否已经注册过
        if is_register(user_name):
            print('%s已经注册过,请重新输入:' % (user_name))
            continue
        print('用户名可用!')
        break
    # 2.输入密码
    while True:
        password = input('请输入密码(6-16位):')
        if not 6 <= len(password) <= 16:
            print('密码输入有误!')
            continue

        re_password = input('确认密码:')
        if password != re_password:
            print('两次输入的密码不一致,请重新输入!')
            continue
        break

    # 3.保存用户名和密码
    all_user = get_all_user()
    all_user.append({key_user_name: user_name, key_password: password})
    re = file_manager.write_json_file(file_name, all_user)
    if re:
        print('注册成功!')
    else:
        print('注册失败!')
コード例 #7
0
def register():
    # 1.输入用户名
    while True:
        user_name = input('请输入一个用户名(3-10位):')
        # 判断是否符合格式要求
        if not 3 <= len(user_name) <= 10:
            print('输入有误,请重新输入!')
            continue
        # 判断是否已经注册过
        if is_register(user_name):
            print('%s,已经注册过,请重新输入!' % user_name)
            continue
        print('用户名可用!')
        break

    # 2.输入密码
    while True:
        password = input('请输入密码(6-16):')
        if not 6 <= len(password) <= 16:
            print('输入密码有误,请重新输入!')
            continue
        re_password = input('确认密码:')
        if password != re_password:
            print('和第一次输入的密码不一样,请重新输入!')
            continue
        break
    #3. 保存用户名和密码
    all_user = get_all_user()
    all_user.append({key_user_name: user_name, key_password: password})
    re = file_manager.write_json_file(file_name, all_user)
    if re:
        print('注册成功!')
    else:
        print('注册失败!')
コード例 #8
0
def add_student():
    while True:
        name = input("姓名:")
        age = input("年龄:")
        tel = input("电话:")

        #2.产生id
        id, number = creat_id()

        #3.创建学生
        stu = {key_name: name, key_age: age, key_tel: tel, key_id: id}

        #4保存学生信息
        system_info = get_system_info()
        all_student = system_info.get(key_all_student, [])
        all_student.append(stu)

        #5.保存到文件中
        system_info[key_all_student] = all_student
        system_info[key_number] = number
        re = file_manager.write_json_file(user_name + ".json", system_info)
        if re:
            print("添加成功")
        else:
            print("添加失败")

        print("1.继续添加")
        print("2.返回")
        value = input("请选择(1/2):")
        if value == "1":
            continue
        else:
            break
コード例 #9
0
def delete_student():
    del_name = input("输入想要删除的学生的姓名:")
    system_info = get_system_info()
    all_student = get_system_info().get(key_all_student, [])

    for stu in all_student[:]:
        if stu[key_name] == del_name:
            print("想要删除的学生信息为:姓名:%s,学号:%s,年龄:%s,电话:%s" % (stu[key_name],\
                            stu[key_id],stu[key_age],stu[key_tel]))
            value1 = input("是否删除(Y/N):")
            if value1 == "Y":
                all_student.remove(stu)
                print("删除成功!")
                break
            else:
                break
    system_info[key_all_student] = all_student
    file_manager.write_json_file(user_name + ".json", system_info)
コード例 #10
0
def modify_student():
    mod_name = input("请输入想要修改的学生姓名:")
    system_info = get_system_info()
    all_student = get_system_info().get(key_all_student, [])
    for stu in all_student[:]:
        if stu[key_name] == mod_name:
            print("想要修改的学生信息为:姓名:%s,学号:%s,年龄:%s,电话:%s" % (stu[key_name], \
                            stu[key_id], stu[key_age], stu[key_tel]))
            print("1.修改年龄;2.修改电话")
            value2 = input("请选择(1/2):")
            if value2 == "1":
                mod_age = input("修改后的学生年龄为:")
                stu[key_age] = mod_age
                print("修改成功!!")
            elif value2 == "2":
                mod_tel = input("修改后的学生电话为:")
                stu[key_tel] = mod_tel
                print("修改成功!!")

    system_info[key_all_student] = all_student
    file_manager.write_json_file(user_name + ".json", system_info)