码迷,mamicode.com
首页 > 编程语言 > 详细

面向对象的学生管理系统(Python实现)

时间:2020-11-25 12:19:19      阅读:5      评论:0      收藏:0      [点我收藏+]

标签:姓名   学生   dict   for   move   序号   main   turn   对象   

student.py

class Student(object):
    def __init__(self, name, gender, tel):
        self.name = name
        self.gender = gender
        self.tel = tel

    def __str__(self):
        return f‘{self.name}, {self.gender}, {self.tel}‘

managerSystem.py

from student import *

class StudentManager(object):
    def __init__(self):
        self.student_list = []

    def run(self):
        while True:
            self.show_menu()
            menu_num = int(input(‘请输入需要的功能序号:‘))
            if menu_num == 1:
                self.add_student()
            elif menu_num == 2:
                self.delete_student()
            elif menu_num == 3:
                self.modify_student()
            elif menu_num == 4:
                self.search_student()
            elif menu_num == 5:
                self.show_student()
            elif menu_num == 6:
                self.save_student()
            elif menu_num == 7:
                self.load_student()
            elif menu_num == 8:
                break

    @staticmethod
    def show_menu():
        print(‘请选择如下功能:‘)
        print(‘1.添加学员‘)
        print(‘2.删除学员‘)
        print(‘3.修改学员信息‘)
        print(‘4.查询学员信息‘)
        print(‘5.显示所有学员信息‘)
        print(‘6.保存学员信息‘)
        print(‘7.加载学员信息‘)
        print(‘8.退出系统‘)

    def add_student(self):
        name = input(‘请输入您的姓名:‘)
        gender = input(‘请输入您的性别:‘)
        tel = input(‘请输入您的手机号:‘)

        student = Student(name, gender, tel)
        self.student_list.append(student)

        print(self.student_list)

    def delete_student(self):
        del_name = input(‘请输入要删除的学员:‘)

        for i in self.student_list:
            if i.name == del_name:
                self.student_list.remove(i)
                break
            else:
                print(‘查无此人!‘)

        print(self.student_list)

    def modify_student(self):
        modify_name = input(‘请输入要修改的学员的姓名:‘)

        for i in self.student_list:
            if i.name == modify_name:
                i.name = input(‘请输入学员的姓名:‘)
                i.gender = input(‘请输入学员性别:‘)
                i.tel = input(‘请输入学员手机号:‘)
                print(f‘修改学员信息成功,姓名:{i.name}, 性别:{i.gender}, 手机号:{i.tel}‘)
                break
            else:
                print(‘学员不存在‘)

    def search_student(self):
        search_name = input(‘请输入要搜索的学员的姓名:‘)

        for i in self.student_list:
            if search_name == i.name:
                print(f‘姓名:{i.name}, 性别:{i.gender}, 手机号:{i.tel}‘)
            else:
                print(‘查无此人‘)

    def show_student(self):
        print(‘姓名\t\t性别\t\t手机号‘)
        for i in self.student_list:
            print(f‘{i.name}\t\t{i.gender}\t\t{i.tel}‘)

    def save_student(self):
        f = open(‘student.data‘, ‘w‘)
        new_list = [i.__dict__ for i in self.student_list]

        f.write(str(new_list))

        f.close()

    def load_student(self):
        print(‘加载学员信息‘)

main.py

from managerSystem import *

if __name__ == ‘__main__‘:
    student_manager = StudentManager()
    student_manager.run()

面向对象的学生管理系统(Python实现)

标签:姓名   学生   dict   for   move   序号   main   turn   对象   

原文地址:https://www.cnblogs.com/19BigData/p/14014752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!