Student Management System Based on Python

Student management system
The student management system mainly includes: adding student information, deleting student information, modifying student information, viewing all student information, and exiting the system. Among them, the specific requirements are that the student information must include name, gender, and phone number. At the same time, the student system has a certain robustness and can make illegal judgments when entering gender and phone number. The specific code is as follows:

#定义学生列表
stuInfo = []
# 菜单
def Menu():
    print('=' * 30)
    print('学生管理系统')
    print('1.添加学生信息')
    print('2.删除学生信息')
    print('3.修改学生信息')
    print('4.显示所有学生信息')
    print('0.退出系统')
    print('=' * 30)

# 添加学生信息
def addInfo():
    newname = input('输入学生的名字:')
    newsex = input('输入学生的性别: (男/女)')
    sex1='男'
    sex2='女'
    while(newsex.strip() != sex1.strip() and newsex.strip() != sex2.strip()):
        print('输入有误,请重新输入')
        newsex = input('输入学生的性别: (男/女)')
    newphone = input('输入学生的手机号码:')
    while (len(newphone) != 11 or newphone.isdigit ()== False ):
        print('输入有误,请重新输入')
        newphone = input('输入学生的手机号码:')
    newInfo = {}#学生信息字典
    newInfo['name'] = newname
    newInfo['sex'] = newsex
    newInfo['phone'] = newphone
    stuInfo.append(newInfo)

# 删除学生信息
def delInfo():
    delNum = int(input('请输入要删除的序号:')) - 1
    del stuInfo[delNum]

# 修改学生信息
def modifystuInfo():
    stuId = int(input('请输入要修改的学生序号:')) - 1
    newname = input('输入修改后学生的名字:')
    newsex = input('输入修改后学生的性别:')
    sex1 = '男'
    sex2 = '女'
    while (newsex.strip() != sex1.strip() and newsex.strip() != sex2.strip()):
        print('输入有误,请重新输入')
        newsex = input('输入学生的性别: (男/女)')
    newphone = input('输入修改后学生的号码:')
    while (len(newphone) != 11 or newphone.isdigit ()== False ):
        print('输入有误,请重新输入')
        newphone = input('输入学生的手机号码:')
    stuInfo[stuId]['name'] = newname
    stuInfo[stuId]['sex'] = newsex
    stuInfo[stuId]['phone'] = newphone

# 显示所有学生信息
def showstuInfo():
    print('=' * 30)
    print('学生信息如下:')
    print('=' * 30)
    i = 1
    for tempInfo in stuInfo:
        print('%d  %s  %s  %s' % (i, tempInfo['name'], tempInfo['sex'], tempInfo['phone']))
        i += 1

def main():
    while True:
        Menu()  # 打印菜单
        key = input('请输入功能对应的数字:')
        if key == '1':
            addInfo()  # 添加学生信息
        elif key == '2':
            delInfo()  # 删除学生信息
        elif key == '3':
            modifystuInfo()  # 修改学生信息
        elif key == '4':
            showstuInfo()  # 查看学生所有信息
        elif key == '0':  # 退出系统
            quitConfirm = input('真的要退出吗?(Yes or No):')
            if quitConfirm == 'Yes':
                break  # 结束循环
            else:
                print('输入有误,请重新输入')
        else:
            print('输入有误,请重新输入')

main()
Published 8 original articles · Like1 · Visits 381

Guess you like

Origin blog.csdn.net/weixin_42064000/article/details/105570394