天天看點

python學生管理系統1.0版本

# 建立一個清單
list_stuInf = []
# 添加功能
def add() :
    # 循環可添加多個學員
    while True:
        # 添加學員名字 字元串類型
        name = input('請輸入添加的學員姓名,q停止添加:')
        # 停止添加操作 輸入q停止 否則繼續
        if name == 'q':
            break
        else:
            # 将學員姓名添加到清單中
            list_stuInf.append(name)
            print(list_stuInf)
            continue
# 修改功能
def modify():
    # 用索引的方法輸出所有學員
    for x in range(0, len(list_stuInf)):
        rs = list_stuInf[x]
        x = x + 1
        print('學号:%s學員姓名:%s' % (x, rs))
    while True:
        # 選擇要修改的學員索引
        y = int(input('請輸入要修改的學号:'))

        # 判斷索引是否在範圍
        if y > x:
            y = int(input('學号不存在,請重新輸入:'))
        else:
            #修改學員姓名
            a = input('學員姓名修改為:')
            y = y - 1
            list_stuInf[y] = a
            break
# 删除功能
def delInf():
    # 用索引的方法輸出所有學員
    for x in range(0, len(list_stuInf)):
        rs = list_stuInf[x]
        x = x + 1
        print('學号:%s學員姓名:%s' % (x, rs))
    # 選擇要修改的學員索引,判斷索引是否在範圍
    while True:
        # 選擇要修改的學員索引
        z = int(input('請輸入要删除的學号:'))

        # 判斷索引是否在範圍
        if z > x:
            y = int(input('學号不存在,請重新輸入:'))
        else:
            # 删除學員姓名
            z = z - 1
            del list_stuInf[z]
            break

#查詢功能
def display():
    for x in range(0, len(list_stuInf)):
        rs = list_stuInf[x]
        x = x + 1
        print('學号:%s學員姓名:%s' % (x, rs))

while True:
    print('學生管理系統1.0版本:')
    print('1.添加學員')
    print('2.修改學員')
    print('3删除學員 3.1删除全部學員')
    print('4.查詢學員')
    print('0.退出')

    select = int(input('您的選擇是:'))
    while select < 0 or select >4:
        select = float(input('選項有誤,請重新'))
    if select == 1:
        #調用函數
        add()
    if select == 2:
        modify()
    if select == 3:
        delInf()
    if select == 4:
        display()
    if select == 0:
        print('歡迎下次使用!')
        break