The examples in this article share the specific code of the python student management system for your reference. The specific content is as follows
``` name_list =[] # Store student information dictionary, store student information in dictionary, then use list to store dictionary
# menu
def display_menu():print("-"*30)print(" Student Management System v8.8")print("1. Add student information")print("2. Delete student information")print("3. Modify Student information")print("4. Query individual student information")print("5. Query all student information")print("6. Exit the system")print("-"*30)
# Selection of the serial number
def get_choice():
selected_key =input("Please enter the selected serial number:")return selected_key
# Check if gender is legal
def check_sex(new_sex):
flag = True
while flag: if new_sex =='male' or new_sex =='female':
flag = False
else:
new_sex =input("The input gender is wrong, please re-enter (male/female):") return new_sex
# Check if the phone number is legal
def check_phone(new_phone):
flag = True
while flag:if new_phone.isdigit():
flag = False
else:
new_phone =input("The phone number you entered is wrong, please re-enter:")return new_phone
# Check if the student ID is duplicated or incorrect
def check_id(new_id):
flag = True
while flag:
# Check if it is a pure number before considering whether it is a duplicate. If it is not a pure number, pass directly
if new_id.isdigit():for i inrange(len(name_list)):if name_list[i]['id']== new_id:
new_id =check_id(input("The student ID you entered is duplicate, please re-enter:"))
flag = False
else:
new_id =input("The student ID you entered is wrong, please re-enter:")return new_id
# Add student information
def add_name():
new_info ={}
new_id =check_id(input("Please enter student ID:"))
new_info['id']= new_id
new_name =input("Please enter your name:")
new_info['name']= new_name
new_sex =check_sex(input("Please enter gender (male/female):"))
new_info['sex']= new_sex
new_phone =check_phone(input("Please enter the phone number:"))
new_info['phone']= new_phone
name_list.append(new_info)print("Added successfully!")
# Query all student information
def find_all():print("="*30)for name in name_list:print(name['id'], name['name'], name['sex'], name['phone'])print("="*30)
# Delete student information
def del_name():
del_id_is =input("Please enter the student ID to be deleted:")
flag = False
index =0for i inrange(len(name_list)):if name_list[i]['id']== del_id_is:
flag = True
index = i
breakif flag:
name_list.pop(index)print("Delete successfully!")else:print("Student not found! Please check if the student ID is entered correctly!")
# Name modification detail function
def choice_of_name(index):while True:
choice =input("Please enter the student's (1.id 2. Name 3. Gender 4. Telephone number, 5. All changes):") if choice =='5':
new_id =input("Please enter a new student ID:")
name_list[index]['id']= new_id
new_name =input("Please enter a new name:")
name_list[index]['name']= new_name
new_sex =check_sex(input("Please enter gender (male/female):"))
name_list[index]['sex']= new_sex
new_phone =check_phone(input("Please enter the phone number:"))
name_list[index]['phone']= new_phone
break
elif choice =='1':
new_id =input("Please enter a new student ID:")
name_list[index]['id']= new_id
break
elif choice =='2':
new_name =input("Please enter a new name:")
name_list[index]['name']= new_name
break
elif choice =='3':
new_sex =check_sex(input("Please enter gender (male/female):"))
name_list[index]['sex']= new_sex
break
elif choice =='4':
new_phone =check_phone(input("Please enter the phone number:"))
name_list[index]['phone']= new_phone
breakelse:print("The input is wrong, please re-enter!")
# Modify student information
def re_name():
id_is =input("Please enter the student ID to be modified:")
flag = False
index =0
# First find the subscript of the student to be modified
for i inrange(len(name_list)):if name_list[i]['id']== id_is:
flag = True
index = i
breakif flag:choice_of_name(index)print("Modification succeeded!")else:print("Modification failed, student information was not found!")
# Query individual student information
def find_name():
find_id_is =input("Please enter the student ID to be queried:")
flag = False
index =0for i inrange(len(name_list)):if name_list[i]['id']== find_id_is:
flag = True
index = i
breakif flag:print("Student inquired, student information is:")print(name_list[index]['id'], name_list[index]['name'], name_list[index]['sex'], name_list[ index]['phone'])else:print("Student not found!")
def main():
exit_name = True
while exit_name:display_menu()
key =get_choice()if key =='1':add_name()
elif key =='2':del_name()
elif key =='3':re_name()
elif key =='4':find_name()
elif key =='5':find_all()
elif key =='6':
exit_name = False
else:print("Please enter the correct value!")main()
For more learning materials, please pay attention to the topic "Management System Development".
The above is the whole content of this article, I hope it will be helpful to everyone's study.
Recommended Posts