python面向对象版学生信息管理系统

时间:2022-06-18 03:06:05

本文实例为大家分享了python面向对象版的学生信息管理系统的具体代码,供大家参考,具体内容如下

功能:

1.能循环输入内容

2.展示功能

-1.新增名片
-2.显示全部
-3.查询名片
-0.退出系统

3.让用户输入希望执行的操作 例如输入1,2,3,0

4.新增列表

提示用户输入姓名,
输入电话
输入qq号
输入邮箱
提示新增名片成功。

5.显示全部

将所有的名片打印出来,格式如下:
姓名    电话       QQ               邮箱
zs       110    1337765076    110@qq.com

6.查询名片

提示请输入要搜索查找用户的姓名
如果用户存在—>显示用户的信息
-提示用户【1】修改 【2】删除 【0】返回上一级菜单,请选择要执行的操作。
-修改操作,可以修改用户名,电话,qq、邮箱。

删除操作,将用户删除。
返回上一级操作,回到欢迎界面,让用户继续操作。
如果用户不存在–>提示查找的用户不存在。 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
class StudentManger(object):
    student_info_lst = []  # 保存所有学生的信息
    @staticmethod
    def show_menu():
        '''显示所有功能'''
        print('欢迎来到学生管理系统')
        print('新增学员请按[1]')
        print('显示全部请按[2]')
        print('查询学员请按[3]')
        print('退出系统请按[0]')
 
    def add_student(self):
        '''这是新增学员的功能'''
        print('-------新增学员功能-------')
        name = input('请输入姓名:')
        age = input('请输入年龄:')
        gender = input('请输入性别:')
        phone = input('请输入手机:')
        # print(name,age,gender,phone)
        # 将用户输入的信息保存到一个字典中。
        dic = {}
        dic['name'] = name
        dic['age'] = age
        dic['gender'] = gender
        dic['phone'] = phone
        # print(dic)
        # 注意:将用户数的信息保存到全局变量student_info_lst
        # 列表中,让其他功能使用列表中的数据。
        self.student_info_lst.append(dic)
        # print(student_info_lst)
        print('添加成功了...')
 
    def alignment(self,s, space):
        '''输出对齐'''
        s1 = s.encode('gbk')
        space = space - len(s1)
        s = s + ' ' * space
        return s
 
    def show_all_student(self):
        print('-------显示所有的学员功能-------')
        if not self.student_info_lst:
            print('还没有学员呢,请添加学员')
            return
 
        # 显示学员的信息
        name = self.alignment('name', 15)
        age = self.alignment('age', 15)
        gender = self.alignment('gender', 15)
        phone = self.alignment('phone', 15)
        print(name, age, gender, phone)
 
        for dic in self.student_info_lst:
            name = dic['name']
            age = dic['age']
            gender = dic['gender']
            phone = dic['phone']
            name = self.alignment(name, 15)
            age = self.alignment(age, 15)
            gender = self.alignment(gender, 15)
            phone = self.alignment(phone, 15)
            print(name, age, gender, phone)
 
    def modify_student_info(self,old_value, msg):
        '''处理修改用户名时不输入问题'''
        new_name = input(msg)
        if new_name.strip():
            return new_name
        else:
            return old_value
 
    def deal_student(self,dic):
        action_str = input("【1】修改 【2】删除 【0】返回上一级菜单,请选择要执行的操作:")
        if action_str == '1':
            # 第一版修改
            # dic['name'] = input('请输入姓名:')
            # dic['age'] = input('请输入年龄:')
            # dic['gender'] = input('请输入性别:')
            # dic['phone'] = input('请输入电话:')
            # 第二版--输入空格后能继续运行。
            dic['name'] = self.modify_student_info(dic['name'], '请输入姓名:')
            dic['age'] = self.modify_student_info(dic['age'], '请输入年龄:')
            dic['gender'] = self.modify_student_info(dic['gender'], '请输入性别:')
            dic['phone'] = self.modify_student_info(dic['phone'], '请输入电话:')
 
            print('修改成功!!!')
 
        elif action_str == '2':
            self.student_info_lst.remove(dic)
            print('删除成功了!!!')
        elif action_str == '0':
            pass
 
    def search_student_by_name(self):
        '''搜索学生'''
        print('-------欢迎来到查询学员功能-------')
        if self.student_info_lst:
            name = input('请输入要查询学员的姓名:')
            for dic in self.student_info_lst:
                if dic['name'] == name:
                    name = self.alignment('name', 15)
                    age = self.alignment('age', 15)
                    gender = self.alignment('gender', 15)
                    phone = self.alignment('phone', 15)
                    print(name, age, gender, phone)
 
                    name = dic['name']
                    age = dic['age']
                    gender = dic['gender']
                    phone = dic['phone']
                    name = self.alignment(name, 15)
                    age = self.alignment(age, 15)
                    gender = self.alignment(gender, 15)
                    phone = self.alignment(phone, 15)
                    print(name, age, gender, phone)
                    # 处理学生信息
                    self.deal_student(dic)
 
                    break
            else:
                print('not have such student')
        else:
            print('not have student please add student')
 
 
while True:
    StudentManger.show_menu()
    student_manager=StudentManger()
    action_str = input('请输入你要选择数字:')
    lst = ['0', '1', '2', '3']
    if action_str in lst:
        if action_str == '1':
            student_manager.add_student()
        elif action_str == '2':
            student_manager.show_all_student()
        elif action_str == '3':
            student_manager.search_student_by_name()
        elif action_str == '0':
            print('三位慢走,欢迎下次光临')
            break
 
    else:
        print('-------sb 输出错了请重新输入...-------')

运行结果:

python面向对象版学生信息管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/weixin_44239541/article/details/86601664