python實現學員管理系統

2022-10-04 07:48:07 字數 3308 閱讀 2363

python實現學員管理系統這個小程式是我剛剛接觸python時,導師帶著做的第乙個小專案。通過這次練習,我學會了很多東西。下面是具體的**和要求

'''學員管理系統1.0版本

1.新增學員

1.1 輸入要新增的學員

1.2 將學員新增到列表中

2.修改學員

2.1 輸出所有的學員及學員索引(從1開始輸出)

2.2 選擇要修改的學員索引,判斷索引是否在範圍

2.3 輸入要修改的值,根據選擇的索引進行修改

3.刪除學員

3.1 根據序號刪除學員

3.1.1 輸出所有的學員及學員索引(從1開始輸出)

3.1.2 選擇要刪除的學員索引,判斷索引是否在範圍

3.1.3 根據索引刪除學員

3.2 刪除所有學員

4.查詢學員

4.1 輸出程式設計客棧所有的學員及學員索引(從1開始輸出)

0.退出程式

''' 

具體功能**如下:

def add_stu():

"""新增學員

:return: none

"""name = input('請輸入要新增的學員姓名:')

# 將輸入的姓名新增到students列表中

students.append(name)

def query_stu():

"""查詢所有學員

:return: none

"""# 遍歷列表

print('*********學員資訊如下所示:*********')

for x in range(0, len(students)):

name = students[x]

print('* 索引號:%s,姓名:%s ' % (x+1, name))

def modify_stu():

"""修改學員

:return: none

"""# 1.執行查詢學員操作

query_stu()

# 2.選擇要修改的學員索引,並判斷索引是否在範圍

idx = int(input('* 請輸入要修改的學員索引:'))

while idx < 1 or idx > len(students):

# 重新輸入要修改的索引

idx = int(input('* 索引有誤,請重選:'))

# 3.根據選擇的索引,修改列表中的資料

name = input('* 請輸入修改後的姓名(%s):' % students[idx-1])

# 修改索引對應的資料

students[idx-1] = name

print('* 修改成功!')

def delete_stu():

"""刪除學員

:return: none

"""# 1.根據索引刪除單個學員 2.刪除所有學員

print('* a.根據索引刪除')

print('* b.刪除所有學員')

select = input('* 請選擇您的刪除方式:')

while select != 'a' and select != 'b':

select = input('* 選擇有誤,請重選:')

if select == 'a':

# 根據索引刪除

# pass 作用為了保證**完整性,使用pass代替未完成**可以讓程式不報錯

# 1.輸出所有學員資訊

query_stu()

# 2.選擇要刪除的學員索引,判斷索引是否在範圍

idx = int(input('* 請輸入要刪除的學員索引:'))

while idx <1 or idx wacvsef> len(students):

idx = int(input('* 請輸入要刪除的學員索引:'))

# 確認是否要刪除

is_del = input('* 確認要刪除(%s)?y/n:' % students[idx-1])

if is_del == 'y':

# 3.執行刪除

dewacvsefl students[idx-1]

else:

# 刪除所有學員

# del students[:]

# for x in range(0, len(students)):

# del students[0]

# pop() 如果不指定索引,一直移除列表中最後乙個元素

# students.pop()

# while 迴圈刪除

# 當len(students) 為0時,相當於寫了乙個false,表示條件為假,迴圈結束

while len(students):

students.pop()

# 定義乙個用來存放所有學員資訊的容器

students =

# true(可以用數字1表示) false(可以用數字0表示) 布林型別資料

while true:

print('********學員管理系統v1.0*********')

print('* 1.新增學員 *')

print('* 2.修改學員 *')

print('* 3.刪除學員 *')

print('* 4.查詢學員 *')

print('* 0.退出程式 *')

select = int(input(' 請選擇您的操作:'))

while select <0 or select > 4:

select = int(input(' 選擇有誤,請重選:'))

print('**********************************')

if select == 1:

print('執行新增學員操作')

add_stu()

elif select == 2:

print('執行修改學員操作')

modify_stu()

elif select == 3:

print('執行刪除學員操作')

delete_stu()

elif select == 4:

print('執行查詢學員操作')

query_stu()

else:

print('* 感謝您的使用,下次再會! www.cppcns.com *')

break

本文標題: python實現學員管理系統

本文位址: /jiaoben/python/253198.html

python 簡單的實現學員管理系統

輸入姓名,年齡,性別 也可以新增其他類別例如性取向 然後以列表的形式儲存 預設為空列表 功能如下 大概就是這樣子。下面是 import time defmain 主函式 while true sl select function sl user input input select your ope...

Python實現學生管理系統

from prettytable import prettytable class studentinfo def init self print print 學生管理系統 v1.0 print 1 新增學生 print 2 顯示所有學生 print 3 查詢學生 print 4 修改學生 prin...

用Python實現學生管理系統

實現簡單的學生管理系統 import os,pickle stu dic filename stu inf.txt class student def init self,name,age,stu id,gender self.name name self.age age self.stu id s...