项目目录
1、界面菜单:
- 添加学生(姓名、电话(不可以重复)、地址、爱好),并自动生成ID(不可以重复)
- 查看所有学生信息(只显示ID、姓名、电话)
- 根据ID删除学生
- 根据指定ID查看一个学生详细信息(所有信息都要显示)
- 根据电话查找学生,并查看详细信息
- 根据姓名查看所有同名学生(ID和电话)
- 通过ID找到学生,并修改学生信息
- 每次选择操作后重新提示用户进行选择操作。
2.>>>提示用户输入菜单中的序号(1,2,3,4,5,6, 7):
3.增加持久化功能
项目分析及实施
1.创建项目菜单模块(student_menu.py模块)
class Student:
print('*********学生电话薄管理系统界面*********')
print()
print('1. 添加学生(姓名、电话(不可以重复)、地址、爱好),并自动生成ID(不可以重复)')
print('2. 查看所有学生信息(只显示ID、姓名、电话)')
print('3. 根据ID删除学生')
print('4. 根据指定ID查看一个学生详细信息(所有信息都要显示) ')
print('5. 根据电话查找学生,并查看详细信息')
print('6. 根据姓名查看所有同名学生(ID和电话')
print('7. 通过ID找到学生,并修改学生信息')
student=Student()
2.创建项目主模块(main_student.py模块)
from package01 import student_menu
def show1():
return student_menu
show1()
student_message = []
while True:
user_input = int(input('请您选择输入1-7的序号:'))
class Add:
def show(self):
if user_input == 1:
print('------添加------')
dict1 = dict()
dict1['姓名'] = input('请输入学生姓名:')
dict1['电话'] = int(input('请输入学生电话:'))
dict1['地址'] = input('请输入学生地址:')
dict1['爱好'] = input('请输入学生爱好:')
dict1['ID'] = len(student_message)+1
student_message.append(dict1)
# print(dict1)
print(student_message)
add = Add()
add.show()
class Check_all_student(Add):
if user_input == 2:
print('------查看------')
for i in range(0, len(student_message)):
first = student_message[i]
# dict2 = first
print('姓名:', first['姓名'], '\n电话:', first['电话'], '\nID:', first['ID'], '\n')
check = Check_all_student()
class Delete(Add):
def delete_student(self):
if user_input == 3:
print('------删除------')
num_id = int(input('请输入要删除学生的ID号:'))
for i in range(len(student_message)):
if student_message[i]['ID'] == num_id:
student_message.remove(student_message[i])
break
else:
print('输入的ID,不存在!')
delete.delete_student()
print(student_message)
delete = Delete()
delete.delete_student()
class Check_one_student(Add):
def setID(self):
if user_input == 4:
numid1 = int(input('请输入学生的ID号:'))
for j in range(len(student_message)):
if student_message[j]['ID'] == numid1:
print(student_message[j])
check_one_st = Check_one_student()
check_one_st.setID()
class Check_phone_student(Add):
def set_phone(self):
if user_input == 5:
num_phone = int(input('请输入学生的电话:'))
for k in range(len(student_message)):
if student_message[k]['电话'] == num_phone:
print(student_message[k])
check_phone_st = Check_phone_student()
check_phone_st.set_phone()
class Chect_name(Add):
def chect_name_student(self):
if user_input == 6:
num_name = input('请输入学生的姓名:')
for v in range(len(student_message)):
if student_message[v]['姓名'] == num_name:
print('ID:', student_message[v]['ID'], '\n电话:', student_message[v]['电话'])
check_name = Chect_name()
check_name.chect_name_student()
class Find(Add):
def find_student(self):
if user_input == 7:
numid2 = int(input('情输入学生的ID号:'))
for p in range(len(student_message)):
if student_message[p]['ID'] == numid2:
student_message[p]['姓名'] = input('请输入修改的新名字:')
student_message[p]['电话'] = int(input('请输入修改的新电话:'))
student_message[p]['地址'] = input('请输入修改的新地址:')
student_message[p]['爱好'] = input('请输入修改的新爱好:')
# print(p)
print(student_message)
find = Find()
find.find_student()
3.创建运行结果模块(result_student.py模块)
from package01 import student_menu, main_student
def show():
return student_menu, main_student
show()