Python 을 이용 하여 학생 정보 관리 시스템 의 완전한 인 스 턴 스 를 실현 합 니 다.

항목 요구:

문 제 를 다 읽 으 면 우선 우 리 는 프로그램의 방향 을 확정 해 야 한다.
우 리 는 모두 유형 을 통 해 실현 해 야 한다.
즉,우 리 는 관리자,학생,강사,과정,교사 등 다섯 가지 유형 을 실현 해 야 한다.
관리자 클래스

class Administration(object):
 def __init__(self):
  self.data = self.__load()
  self.login_data = {}

 def __load(self) -> list:
  try:
   Adm = open('Administration.csv', 'r')
   readers = csv.DictReader(Adm)
   Adm_dict = [dict(i) for i in readers]
   Adm.close()
   return Adm_dict
  except Exception:
   print('      ')

 def see_course(self):
  print('          :')
  for i in cou.data:
   print(i)
  print()

 def see_student(self):
  print('          :')
  for i in stu.data:
   print(i)
  print()

 def see_student_course(self):
  print('            :')
  for i in stu.data:
   print(i['  '], '      :', i['  '])
  print()

 def set_course(self):
  name = input('           ')
  c = [i['  '] for i in cou.data]
  if name in c:
   print('             ')
  else:
   cou.data.append({'  ': name, '  ': 0})
   print('    !')
   print()

 def set_student(self):
  name = input('             ')
  ID = input('       ID')
  if ID in [i['ID'] for i in stu.data]:
   print('  ID    ,    ')
   return
  print('        123456')
  password = 123456
  stu.data.append({'  ': name, 'ID': ID, '  ': password, '  ': ''})
  print('    !')
  print()

 def set_teacher(self):
  name = input('             ')
  ID = input('       ID')
  if ID in [i['ID'] for i in tea.data]:
   print('  ID    ,    ')
   return
  print('        123456')
  password = 123456
  tea.data.append({'  ': name, 'ID': ID, '  ': password, '  ': ''})
  print('    !')
  print()

 def app_teacher_to_class(self):
  t_name = input('           ')
  if t_name not in [i['  '] for i in tea.data]:
   print('          ,     ')
   return
  c_name = input('              ')
  if c_name not in [i['  '] for i in cla.data]:
   print('             ,     ')
   return
  for i in tea.data:
   if i['  '] == t_name:
    i['  '] = c_name
  for i in cla.data:
   if i['  '] == c_name:
    i['    '] = t_name
  print('    ')

 def set_class(self):
  name = input('             :')
  if name in [i['  '] for i in cla.data]:
   print('           ,     ')
   return
  if int(input('        ,   1,   0')):
   t_name = input('           ')
   if t_name not in [i['  '] for i in tea.data]:
    print('          ,     ')
    return
  else:
   t_name = ''
  s_name_list = []
  while int(input('      ,   1,   0')):
   s_name = input('          ')
   if s_name not in [i['  '] for i in stu.data]:
    print('          ,     ')
    return
   else:
    s_name_list.append(s_name)
  s_name = ''
  if s_name_list == []:
   cla.data.append({'  ': name, '    ': t_name, '  ': s_name})
   print('    ')
  else:
   cla.data.append({'  ': name, '    ': t_name,
        '  ': s_name.join(s_name_list)})
   print('    ')

 def app_student_to_class(self):
  s_name = input('           ')
  if s_name not in [i['  '] for i in stu.data]:
   print('          ,     ')
   return
  c_name = input('              ')
  if c_name not in [i['  '] for i in cla.data]:
   print('             ,     ')
   return
  for i in stu.data:
   if i['  '] == s_name:
    i['  '] = c_name
  for i in cla.data:
   if i['  '] == c_name:
    i['    '] = s_name
  print('    ')

 def save(self):
  try:
   j = open('Administration.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
   j.close()
  except Exception:
   print('      ')
학생 류

class Student(object):
 def __init__(self):
  self.data = self.__load()
  self.login_data = {}

 def __load(self):
  try:
   Stu = open('Student.csv', 'r')
   readers = csv.DictReader(Stu)
   Stu_dict = [dict(i) for i in readers]
   Stu.close()
   return Stu_dict
  except Exception:
   print('      ')

 def see_course(self):
  print('          :')
  for i in cou.data:
   print(i)
  print()

 def choice_course(self):
  # print(self.data)
  c = [i['  '] for i in cou.data]
  c_name = input('           :')
  if c_name not in c:
   print('             ')
   return
  else:
   self.login_data['  ']: str = self.login_data['  '] + c_name + ' '
   for i in cou.data:
    if i['  '] == c_name:
     i['  '] = int(i['  ']) + 1
  print('    ')

 def see_own_course(self):
  if self.login_data['  '] == '':
   print('        ')
  else:
   print(self.login_data['  '])

 def save(self):
  try:
   j = open('Student.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
  except Exception:
   print('      ')
교과 과정

class Course(object):
 def __init__(self):
  self.data = self.__load()

 def __load(self):
  try:
   Cou = open('Course.csv', 'r')
   readers = csv.DictReader(Cou)
   Cou_dict = [dict(i) for i in readers]
   Cou.close()
   return Cou_dict
  except Exception:
   print('      ')

 def save(self):
  try:
   j = open('Course.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
  except Exception:
   print('      ')
교실

class Classroom(object):
 def __init__(self):
  self.data = self.__load()

 def __load(self):
  try:
   Cla = open('Classroom.csv', 'r')
   readers = csv.DictReader(Cla)
   Cla_dict = [dict(i) for i in readers]
   Cla.close()
   return Cla_dict
  except Exception:
   print('      ')

 def save(self):
  try:
   j = open('Classroom.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
  except Exception:
   print('      ')
교사 류

class Teacher(object):
 def __init__(self):
  self.data = self.__load()
  self.login_data = {}

 def __load(self):
  try:
   Tea = open('Teacher.csv', 'r')
   readers = csv.DictReader(Tea)
   Tea_dict = [dict(i) for i in readers]
   Tea.close()
   return Tea_dict
  except Exception:
   print('      ')

 def see_course(self):
  print('          :')
  for i in cou.data:
   print(i)
  print()

 def see_class(self):
  print('     :', self.login_data['  '])
  print()

 def see_class_student(self):
  print('         :')
  for i in cla.data:
   if i['  '] == self.login_data['  ']:
    print(i['  '])
  print()

 def save(self):
  try:
   j = open('Teacher.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
  except Exception:
   print('      ')
전체 코드 는 다음 과 같 습 니 다:

import csv
import time


class Administration(object):
 def __init__(self):
  self.data = self.__load()
  self.login_data = {}

 def __load(self) -> list:
  try:
   Adm = open('Administration.csv', 'r')
   readers = csv.DictReader(Adm)
   Adm_dict = [dict(i) for i in readers]
   Adm.close()
   return Adm_dict
  except Exception:
   print('      ')

 def see_course(self):
  print('          :')
  for i in cou.data:
   print(i)
  print()

 def see_student(self):
  print('          :')
  for i in stu.data:
   print(i)
  print()

 def see_student_course(self):
  print('            :')
  for i in stu.data:
   print(i['  '], '      :', i['  '])
  print()

 def set_course(self):
  name = input('           ')
  c = [i['  '] for i in cou.data]
  if name in c:
   print('             ')
  else:
   cou.data.append({'  ': name, '  ': 0})
   print('    !')
   print()

 def set_student(self):
  name = input('             ')
  ID = input('       ID')
  if ID in [i['ID'] for i in stu.data]:
   print('  ID    ,    ')
   return
  print('        123456')
  password = 123456
  stu.data.append({'  ': name, 'ID': ID, '  ': password, '  ': ''})
  print('    !')
  print()

 def set_teacher(self):
  name = input('             ')
  ID = input('       ID')
  if ID in [i['ID'] for i in tea.data]:
   print('  ID    ,    ')
   return
  print('        123456')
  password = 123456
  tea.data.append({'  ': name, 'ID': ID, '  ': password, '  ': ''})
  print('    !')
  print()

 def app_teacher_to_class(self):
  t_name = input('           ')
  if t_name not in [i['  '] for i in tea.data]:
   print('          ,     ')
   return
  c_name = input('              ')
  if c_name not in [i['  '] for i in cla.data]:
   print('             ,     ')
   return
  for i in tea.data:
   if i['  '] == t_name:
    i['  '] = c_name
  for i in cla.data:
   if i['  '] == c_name:
    i['    '] = t_name
  print('    ')

 def set_class(self):
  name = input('             :')
  if name in [i['  '] for i in cla.data]:
   print('           ,     ')
   return
  if int(input('        ,   1,   0')):
   t_name = input('           ')
   if t_name not in [i['  '] for i in tea.data]:
    print('          ,     ')
    return
  else:
   t_name = ''
  s_name_list = []
  while int(input('      ,   1,   0')):
   s_name = input('          ')
   if s_name not in [i['  '] for i in stu.data]:
    print('          ,     ')
    return
   else:
    s_name_list.append(s_name)
  s_name = ''
  if s_name_list == []:
   cla.data.append({'  ': name, '    ': t_name, '  ': s_name})
   print('    ')
  else:
   cla.data.append({'  ': name, '    ': t_name,
        '  ': s_name.join(s_name_list)})
   print('    ')

 def app_student_to_class(self):
  s_name = input('           ')
  if s_name not in [i['  '] for i in stu.data]:
   print('          ,     ')
   return
  c_name = input('              ')
  if c_name not in [i['  '] for i in cla.data]:
   print('             ,     ')
   return
  for i in stu.data:
   if i['  '] == s_name:
    i['  '] = c_name
  for i in cla.data:
   if i['  '] == c_name:
    i['    '] = s_name
  print('    ')

 def save(self):
  try:
   j = open('Administration.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
   j.close()
  except Exception:
   print('      ')


class Student(object):
 def __init__(self):
  self.data = self.__load()
  self.login_data = {}

 def __load(self):
  try:
   Stu = open('Student.csv', 'r')
   readers = csv.DictReader(Stu)
   Stu_dict = [dict(i) for i in readers]
   Stu.close()
   return Stu_dict
  except Exception:
   print('      ')

 def see_course(self):
  print('          :')
  for i in cou.data:
   print(i)
  print()

 def choice_course(self):
  # print(self.data)
  c = [i['  '] for i in cou.data]
  c_name = input('           :')
  if c_name not in c:
   print('             ')
   return
  else:
   self.login_data['  ']: str = self.login_data['  '] + c_name + ' '
   for i in cou.data:
    if i['  '] == c_name:
     i['  '] = int(i['  ']) + 1
  print('    ')

 def see_own_course(self):
  if self.login_data['  '] == '':
   print('        ')
  else:
   print(self.login_data['  '])

 def save(self):
  try:
   j = open('Student.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
  except Exception:
   print('      ')


class Course(object):
 def __init__(self):
  self.data = self.__load()

 def __load(self):
  try:
   Cou = open('Course.csv', 'r')
   readers = csv.DictReader(Cou)
   Cou_dict = [dict(i) for i in readers]
   Cou.close()
   return Cou_dict
  except Exception:
   print('      ')

 def save(self):
  try:
   j = open('Course.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
  except Exception:
   print('      ')


class Classroom(object):
 def __init__(self):
  self.data = self.__load()

 def __load(self):
  try:
   Cla = open('Classroom.csv', 'r')
   readers = csv.DictReader(Cla)
   Cla_dict = [dict(i) for i in readers]
   Cla.close()
   return Cla_dict
  except Exception:
   print('      ')

 def save(self):
  try:
   j = open('Classroom.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
  except Exception:
   print('      ')


class Teacher(object):
 def __init__(self):
  self.data = self.__load()
  self.login_data = {}

 def __load(self):
  try:
   Tea = open('Teacher.csv', 'r')
   readers = csv.DictReader(Tea)
   Tea_dict = [dict(i) for i in readers]
   Tea.close()
   return Tea_dict
  except Exception:
   print('      ')

 def see_course(self):
  print('          :')
  for i in cou.data:
   print(i)
  print()

 def see_class(self):
  print('     :', self.login_data['  '])
  print()

 def see_class_student(self):
  print('         :')
  for i in cla.data:
   if i['  '] == self.login_data['  ']:
    print(i['  '])
  print()

 def save(self):
  try:
   j = open('Teacher.csv', 'w')
   writer = csv.writer(j)
   writer.writerow(list(self.data[0].keys()))
   data = [list(i.values()) for i in self.data]
   writer.writerows(data)
  except Exception:
   print('      ')


def login(ID, password) -> int:
 #         
 for i in adm.data:
  if ID == i['ID'] and password == i['  ']:
   adm.login_data = i
   return 1
 #        
 for i in stu.data:
  if ID == i['ID'] and password == i['  ']:
   stu.login_data = i
   return 2
 #        
 for i in tea.data:
  if ID == i['ID'] and password == i['  ']:
   tea.login_data = i
   return 3
 return 0


if __name__ == '__main__':
 print('            ')
 time.sleep(0.5)
 print('     ~')
 adm = Administration()
 stu = Student()
 cou = Course()
 tea = Teacher()
 cla = Classroom()
 time.sleep(0.3)
 print('    ')
 while True:
  ID = input('       :')
  password = input('       :')
  flag = login(ID, password)
  if not flag:
   print('          ')
   flag_1 = int(input('             1       0'))
   if flag_1:
    continue
   else:
    break
  elif flag == 1:
   print('     ')
   break
  elif flag == 2:
   print('    ')
   break
  elif flag == 3:
   print('    ')
   break
 if flag == 1:
  while True:
   check = int(
    input(
     '1.    
2.
3.
4.
5.
6. ' '
7.
8.
9.
10. ')) if check == 1: adm.set_course() elif check == 2: adm.set_student() elif check == 3: adm.see_course() elif check == 4: adm.see_student() elif check == 5: adm.see_student_course() elif check == 6: adm.set_teacher() elif check == 7: adm.app_teacher_to_class() elif check == 8: adm.set_class() elif check == 9: adm.app_student_to_class() elif check == 10: break elif flag == 2: while True: check = int(input('1.
2.
3.
4. ')) if check == 1: stu.see_course() elif check == 2: stu.see_own_course() elif check == 3: stu.choice_course() elif check == 4: break elif flag == 3: while True: check = int(input('1.
2.
3.
4. ')) if check == 1: tea.see_course() elif check == 2: tea.see_class() elif check == 3: tea.see_class_student() elif check == 4: break print(' ~') adm.save() tea.save() stu.save() cla.save() cou.save() time.sleep(0.5) print(' !')
전체 시스템 의 데 이 터 는 모두 단독으로 존재 하 며 csv 파일 에 저 장 됩 니 다.
효과 그림:

총결산
파 이 썬 을 이용 하여 학생 정보 관리 시스템 을 실현 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 파 이 썬 이 학생 정보 관리 시스템 을 실현 하 는 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!

좋은 웹페이지 즐겨찾기