python 학생 관리 시스템 원본 구현

본 논문 의 사례 는 python 이 학생 관리 시스템 을 실현 하 는 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.
프로 세 스 지향

import os

stu_list = []


def show_menu():
    print('1.    ')
    print('2.    ')
    print('3.      ')
    print('4.        ')
    print('5.        ')
    print('6.    ')


def insert_student():
    name = input('       :')
    for stu in stu_list:
        if stu['name'] == name:
            print('.........       ........')
            return
    age = input('       :')
    gender = input('       :')
    stu_dict = {'name': name, 'age': int(age), 'gender': gender}
    stu_list.append(stu_dict)
    print("        !")


def remove_student():
    name = input('            :')
    for stu in stu_list:
        if stu['name'] == name:
            stu_list.remove(stu)
            print('    !')
            break
    else:
        print('........        ,    .........')


def modify_student():
    name = input('            :')
    for stu in stu_list:
        if stu['name'] == name:
            stu['age'] = int(input('       :'))
            print('    !')
            break
    else:
        print('........        ,    .........')


def search_student():
    name = input('            :')
    for stu in stu_list:
        if stu['name'] == name:
            print(f'  :{stu["name"]},  :{stu["age"]},  :{stu["gender"]}')
            break
    else:
        print('........        .......')


def show_all_stu():
    if len(stu_list):
        for stu in stu_list:
            print(f'  :{stu["name"]},  :{stu["age"]},  :{stu["gender"]}')
    else:
        print("        !")


def save():
    f = open('student.txt', 'w')
    f.write(str(stu_list))
    f.close()


def read_file():
    global stu_list
    if os.path.exists('student.tct'):
        f = open('student.txt', 'r', encoding='utf-8')
        buf = f.read()
        if buf:
            stu_list = eval(buf)
        f.close()


def main():
    read_file()
    while True:
        show_menu()
        opt = input('          :')
        if opt == '1':
            print('1.    ')
            insert_student()
        elif opt == '2':
            print('2.    ')
            remove_student()
        elif opt == '3':
            print('3.        ')
            modify_student()
        elif opt == '4':
            print('        ')
            search_student()
        elif opt == '5':
            print('5.        ')
            show_all_stu()
        elif opt == '6':
            print('         ')
            save()
            break
        else:
            print('    ,     ')
            continue
        input('........       ........')


main()
대상 판
1.프로젝트 파일

2.main.py

import student_manage_sysytem as sms

if __name__ == '__main__':
    stu_sms = sms.StudenManagerSystem()
    stu_sms.start()
3.student.py

class Student():
    def __init__(self, stu_id, name, age, gender):
        self.sut_id = stu_id
        self.name = name
        self.age = age
        self.gender = gender

    def __str__(self):
        return f"{self.sut_id},{self.name},{self.age},{self.gender}"
4.student_manage_system.py

import student


class StudenManagerSystem():
    def __init__(self):
        self.stu_dict = {}

    @staticmethod
    def __show_menu():
        print('1.    ')
        print('2.    ')
        print('3.      ')
        print('4.        ')
        print('5.        ')
        print('6.    ')

    def __insert_student(self):
        stu_id = input('       :')
        if stu_id in self.stu_dict:
            print('        ,       ')
            return
        name = input('       :')
        age = input('       :')
        gender = input('       :')
        stu = student.Student(stu_id, name, age, gender)
        self.stu_dict[stu_id] = stu

    def __removw_student(self):
        stu_id = input('     :')
        if stu_id in self.stu_dict:
            del self.stu_dict[stu_id]
            print('      ')
        else:
            print('       ,    ')

    def __modify_student(self):
        stu_id = input('     :')
        if stu_id in self.stu_dict:
            stu = self.stu_dict[stu_id]
            stu.age = input('       :')
            print('        ')
        else:
            print('       ,    ')

    def __search_student(self):
        stu_id = input('     :')
        if stu_id in self.stu_dict:
            stu = self.stu_dict[stu_id]
            print(stu)
        else:
            print('       ')

    def __save(self):
        f = open('student.txt', 'w', encoding='utf-8')
        for stu in self.stu_dict.values():
            f.write(str(stu) + '
') f.close() def __load_info(self): try: f = open('student.txt', 'r', encoding='utf-8') buf_list = f.readlines() for buf in buf_list: buf = buf.strip() info_list = buf.split(',') stu = student.Student(*info_list) stu_id = info_list[0] self.stu_dict[stu_id] = stu f.close() except Exception: pass def __show_all_info(self): for stu in self.stu_dict.values(): print(stu) def start(self): self.__load_info() while True: self.__show_menu() opt = input(' :') if opt == '1': print('1. ') self.__insert_student() elif opt == '2': print('2. ') self.__removw_student() elif opt == '3': print('3. ') self.__modify_student() elif opt == '4': print(' ') self.__search_student() elif opt == '5': print('5. ') self.__show_all_info() elif opt == '6': self.__save() print(' ') break else: print(' , ') continue input('........ ........')
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기