Python Student Information Management System Tutorial
This tutorial presents a step‑by‑step guide to building a simple Python student information management system, covering system overview, functional requirements, detailed code implementation for adding, deleting, modifying, searching, and displaying student records, and demonstrates the interactive console workflow with example screenshots.
This article describes how to create a console‑based student information management system using Python. It begins with a brief system introduction, listing the main functions: add, delete, modify, search, display student records, and exit the program.
System Overview
The system operates in a loop until the user selects option 6 to quit. The user is presented with a menu, inputs a function number, and the corresponding function is executed.
Step‑by‑Step Analysis
Display the menu interface.
Prompt the user to enter a function number.
Call the appropriate function based on the input.
Function Implementations
The core functions are defined as follows:
# Define a function to print the menu
def info_print():
print('--------请选择功能-----')
print('1、添加学生')
print('2、删除学生')
print('3、修改学生')
print('4、查询学生')
print('5、显示所有学生')
print('6、退出系统')
print('-' * 20)
# Global list to store student dictionaries
info = []Add Student Information
def add_info():
"""添加学生函数"""
# Receive user input
new_id = input("输入学号:")
new_name = input("输入姓名:")
new_tel = input("输入手机号:")
# Prevent duplicate names
for i in info:
if new_name == i['name']:
print("此用户已经存在,请勿重复添加")
return
# Append new student dictionary
info_dict = {'id': new_id, 'name': new_name, 'tel': new_tel}
info.append(info_dict)
print(info)Delete Student Information
def del_info():
"""删除学生"""
del_name = input("请输入要删除的学生的姓名:")
for i in info:
if del_name == i['name']:
info.remove(i)
break
else:
print('该学生不存在!')
print(info)Modify Student Information
def modify_info():
"""修改函数"""
modify_name = input("请输入要修改的学生的姓名:")
for i in info:
if modify_name == i['name']:
i['tel'] = input("请输入新的手机号:")
break
else:
print("该学生不存在")
print(info)Search Student Information
def search_info():
"""查询学生信息"""
search_name = input("请输入要查找的学生姓名:")
for i in info:
if search_name == i['name']:
print("找到该学生的信息如下:")
print(f"该学生的学号是{i['id']},姓名是{i['name']},手机号是{i['tel']}")
break
else:
print("该学生不存在!")Display All Students
def print_all():
"""显示所有学生信息"""
print('学号\t姓名\t手机号')
for i in info:
print(f"{i['id']}\t{i['name']}\t{i['tel']}")Main Loop
while True:
info_print()
user_num = eval(input('请输入功能序号:'))
if user_num == 1:
add_info()
elif user_num == 2:
del_info()
elif user_num == 3:
modify_info()
elif user_num == 4:
search_info()
elif user_num == 5:
print_all()
elif user_num == 6:
exit_flag = input("确定要退出吗?yes/no?")
if exit_flag == 'yes':
break
else:
print('输入的功能序号有误!')The article also includes screenshots of the program’s runtime showing adding, deleting, modifying, searching, and displaying student data, followed by a QR code that advertises free Python learning resources (which is promotional content outside the tutorial).
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.