本文将通过建立学生学籍管理系统,总结python基础内容,并扩充细节知识点
项目演示
目标
- 搭建学籍管理系统框架结构1
- 准备工程
- 编写主要运行循环,实现用户输入和判断
- 编写工具模块,实现学籍管理系统的增删改查
stu_main.py 文件
while True: # 无限循环保证程序不退出
print('Student Management System')
print('--------------------------')
print('1. Add student')
print('2. Delete student')
print('3. Modify student')
print('4. Search student')
print('5. Display all students')
print('6. Exit')
print('--------------------------')
choice = int(input('Enter your choice: '))
print("You entered: ", choice)
if choice == 1:
pass
elif choice == 2:
pass
elif choice == 3:
pass
elif choice == 4:
pass
elif choice == 5:
pass
elif choice == 6:
break
else:
print('Invalid choice')
pass 关键字
如果在开发程序时,不想立刻编写分支内部的代码。可以使用pass关键字,表示一个占位符,保证程序的结构正确,程序运行时,pass不会执行任何操作。
#TODO 代码注释
- TODO 必须大写,方便查看要完成的代码块
- 使用TODO 注释,配合IDE,可以快速找到未完成的代码块
Pycharm 重命名标识符
选中标识符,按Shift+F6,可以批量重命名
stu_tool.py 文件
students = []
def print_menu():
'''
Print the menu
:return:
'''
print()
print('Student Management System')
print('--------------------------')
print('1. Add student')
print('2. Delete student')
print('3. Modify student')
print('4. Search student')
print('5. Display all students')
print('6. Exit')
print('--------------------------')
def display_student(s