Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Student:
- def __init__(self, fname, lname, fnum):
- self.fname = fname
- self.lname = lname
- self.fnum = fnum
- class Project:
- def __init__(self, title):
- self.title = title
- self.participants = {}
- class Participant:
- def __init__(self, fnum, project_title):
- self.fnum = fnum
- self.project_title = project_title
- class UniversitySystem:
- def __init__(self):
- self.students = []
- self.projects = []
- self.participants = []
- def add_student(self):
- print("Добавяне на студент")
- fname = input("Въведете име: ")
- lname = input("Въведете фамилия: ")
- fnum = input("Въведете факултетен номер: ")
- students = Student(fname, lname, fnum)
- self.students.append(students)
- print("You have successfully added a student: %s" %fname )
- print()
- def save_to_file_students(self, StudentsList):
- with open(StudentsList, 'w') as file:
- for student in self.students:
- file.write(f"Списък със студнетите: \n{student.fname} {student.lname}, {student.fnum}\n")
- def add_project(self):
- print("Добавяне на проект")
- title = input("Въведете име на проекта: ")
- project = Project(title)
- self.projects.append(project)
- print("You have successfully added a project: %s" %title)
- print()
- def save_to_file_projects(self, ProjectsList):
- with open(ProjectsList, 'w') as file:
- for project in self.projects:
- file.write(f"Списък с проектите: \n{project.title}\n")
- def save_to_file_participants(self, ParticipantsList):
- with open(ParticipantsList, 'w') as file:
- for participant in self.participants:
- file.write(f"Списък с участниците в проектите: \n{participant.fnum}, {participant.project_title}\n")
- def assign_student_to_project(self, StudentsList, ProjectsList):
- with open(StudentsList, 'r') as student_file, open(ProjectsList, 'r') as project_file:
- file_content_students = student_file.read()
- file_content_projects = project_file.read()
- print(file_content_students)
- print(file_content_projects)
- fnum = input("въведете факултетен номер на студента: \n")
- project_title = input("въведете заглавие на проекта: \n")
- if fnum in file_content_students and project_title in file_content_projects:
- participant = Participant(fnum, project_title)
- self.participants.append(participant)
- print("Студентът е записан за участие в проект!")
- self.save_to_file_participants("ParticipantsList.txt")
- def read_to_file_participants(self, ParticipantsList):
- with open(ParticipantsList, 'r') as file:
- file_content_students = file.read()
- print(file_content_students)
- def display_menu():
- print("----------------------------------------------------------\n"
- "| Студентска система |\n"
- "| Изберете следата опция: |\n"
- "| 1 - Добавяне на студент |\n"
- "| 2 - Добавяне на проект |\n"
- "| 3 - Записване на студент за проект |\n"
- "| 4 - Извеждане на списък със студентите и проектите |\n"
- "| 5 - Изход |\n"
- "----------------------------------------------------------\n")
- def main():
- while True:
- university_system = UniversitySystem()
- display_menu()
- a = int(input("Въведете число сътветстващо на желаната опция от менюто: "))
- if a == 1:
- print("1 - Добавяне на студент ")
- b = int(input("Въведете брой студенти: \n"))
- for _ in range(b):
- university_system.add_student()
- university_system.save_to_file_students("StudentsList.txt")
- elif a == 2:
- print("2 - Добавяне на проект")
- b = int(input("Въведете брой проекти: \n"))
- for _ in range(b):
- university_system.add_project()
- university_system.save_to_file_projects("ProdjectsList.txt")
- elif a == 3:
- print("3 - Записване на студент за проект")
- b = int(input("Въведете брой на участниците в проекта: \n"))
- for _ in range(b):
- university_system.assign_student_to_project("StudentsList.txt","ProdjectsList.txt")
- elif a == 4:
- print("Извеждане на списък със студентите и проектите")
- university_system.read_to_file_participants("ParticipantsList.txt")
- elif a == 5:
- print("Изход")
- break
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement