Advertisement
AntoniiaG

Untitled

Jan 18th, 2024
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.55 KB | None | 0 0
  1. class Student:
  2.     def __init__(self, fname, lname, fnum):
  3.         self.fname = fname
  4.         self.lname = lname
  5.         self.fnum = fnum
  6.  
  7. class Project:
  8.     def __init__(self, title):
  9.         self.title = title
  10.         self.participants = {}
  11.        
  12. class Participant:
  13.     def __init__(self, fnum, project_title):
  14.         self.fnum = fnum
  15.         self.project_title = project_title
  16.  
  17. class UniversitySystem:
  18.     def __init__(self):
  19.         self.students = []
  20.         self.projects = []
  21.         self.participants = []
  22.                
  23.     def add_student(self):
  24.         print("Добавяне на студент")
  25.         fname = input("Въведете име: ")
  26.         lname = input("Въведете фамилия: ")
  27.         fnum = input("Въведете факултетен номер: ")
  28.         students = Student(fname, lname, fnum)
  29.         self.students.append(students)
  30.         print("You have successfully added a student: %s" %fname )
  31.         print()
  32.  
  33.     def save_to_file_students(self, StudentsList):
  34.         with open(StudentsList, 'w') as file:
  35.             for student in self.students:
  36.                 file.write(f"Списък със студнетите: \n{student.fname} {student.lname}, {student.fnum}\n")
  37.  
  38.     def add_project(self):
  39.         print("Добавяне на проект")
  40.         title = input("Въведете име на проекта: ")
  41.         project = Project(title)
  42.         self.projects.append(project)
  43.         print("You have successfully added a project: %s" %title)
  44.         print()
  45.  
  46.     def save_to_file_projects(self, ProjectsList):
  47.         with open(ProjectsList, 'w') as file:
  48.             for project in self.projects:
  49.                 file.write(f"Списък с проектите: \n{project.title}\n")
  50.    
  51.     def save_to_file_participants(self, ParticipantsList):
  52.         with open(ParticipantsList, 'w') as file:
  53.             for participant in self.participants:
  54.                 file.write(f"Списък с участниците в проектите: \n{participant.fnum}, {participant.project_title}\n")
  55.  
  56.     def assign_student_to_project(self, StudentsList, ProjectsList):
  57.         with open(StudentsList, 'r') as student_file, open(ProjectsList, 'r') as project_file:
  58.             file_content_students = student_file.read()
  59.             file_content_projects = project_file.read()
  60.             print(file_content_students)
  61.             print(file_content_projects)
  62.             fnum = input("въведете факултетен номер на студента: \n")
  63.             project_title = input("въведете заглавие на проекта: \n")
  64.             if fnum in file_content_students and project_title in file_content_projects:
  65.                 participant = Participant(fnum, project_title)
  66.                 self.participants.append(participant)
  67.                 print("Студентът е записан за участие в проект!")
  68.                 self.save_to_file_participants("ParticipantsList.txt")    
  69.  
  70.     def read_to_file_participants(self, ParticipantsList):
  71.         with open(ParticipantsList, 'r') as file:
  72.             file_content_students = file.read()
  73.             print(file_content_students)
  74.    
  75. def display_menu():
  76.     print("----------------------------------------------------------\n"
  77.           "|      Студентска система                                |\n"
  78.           "|  Изберете следата опция:                               |\n"
  79.           "|  1 - Добавяне на студент                               |\n"
  80.           "|  2 - Добавяне на проект                                |\n"
  81.           "|  3 - Записване на студент за проект                    |\n"
  82.           "|  4 - Извеждане на списък със студентите и проектите    |\n"
  83.           "|  5 - Изход                                             |\n"
  84.           "----------------------------------------------------------\n")
  85.  
  86. def main():
  87.     while True:
  88.         university_system = UniversitySystem()
  89.         display_menu()
  90.         a = int(input("Въведете число сътветстващо на желаната опция от менюто: "))
  91.         if a == 1:
  92.             print("1 - Добавяне на студент ")
  93.             b = int(input("Въведете брой студенти: \n"))
  94.             for _ in range(b):  
  95.                 university_system.add_student()
  96.             university_system.save_to_file_students("StudentsList.txt")
  97.         elif a == 2:
  98.             print("2 - Добавяне на проект")
  99.             b = int(input("Въведете брой проекти: \n"))
  100.             for _ in range(b):
  101.                 university_system.add_project()
  102.             university_system.save_to_file_projects("ProdjectsList.txt")
  103.         elif a == 3:
  104.             print("3 - Записване на студент за проект")
  105.             b = int(input("Въведете брой на участниците в проекта: \n"))
  106.             for _ in range(b):
  107.                 university_system.assign_student_to_project("StudentsList.txt","ProdjectsList.txt")
  108.         elif a == 4:
  109.             print("Извеждане на списък със студентите и проектите")
  110.             university_system.read_to_file_participants("ParticipantsList.txt")          
  111.         elif a == 5:
  112.             print("Изход")
  113.             break
  114.        
  115. if __name__ == "__main__":
  116.     main()
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement