Пример #1
0
def main():
    courses = Courses()
    students = Students()
    teachers = Teachers()
    while True:
        print("\nMain Menu")
        print(f"{20 * '-'}")
        print("1. Manage Students")
        print("2. Manage Teachers")
        print("3. Manage Course")
        print("4. Exit")
        while True:
            choice = input("Pick one: ")
            if not choice.isdigit():
                print("Give a number please")
                continue
            choice = int(choice)
            if choice < 1 or choice > 4:
                print("Index out of borders")
            else:
                break
        if choice == 1:
            while True:
                print("\nManage Students")
                print(f"{20 * '-'}")
                print("1. Create Student")
                print("2. Add Course to Students")
                print("3. Read Students")
                print("4. Update Students")
                print("5. Delete Students")
                print("6. Back to Main Menu")
                while True:
                    manage_student_choice = input("Pick one: ")
                    if not manage_student_choice.isdigit():
                        print("Give a number please")
                        continue
                    manage_student_choice = int(manage_student_choice)
                    if manage_student_choice < 1 or manage_student_choice > 6:
                        print("Index out of borders")
                    else:
                        break

                if manage_student_choice == 1:  # CREATE STUDENT
                    print("\nINSERT STUDENT")
                    print(f"{20 * '-'}")
                    create_student(students)
                elif manage_student_choice == 2:  # ADD COURSE TO STUDENT
                    print("\nADD COURSE TO STUDENT")
                    print(f"{20 * '-'}")
                    add_course_to_student(students, courses)
                elif manage_student_choice == 3:  # READ STUDENTS
                    while True:
                        print("\nREAD STUDENTS")
                        print(f"{20 * '-'}")
                        print("1. Read a student id")
                        print("2. Read all students")
                        print("3. Back to Students Menu")
                        while True:
                            read_students_choice = input("Pick one: ")
                            if not read_students_choice.isdigit():
                                print("Give a number please")
                                continue
                            read_students_choice = int(read_students_choice)
                            if read_students_choice < 1 or read_students_choice > 3:
                                print("Index out of borders")
                            else:
                                break
                        if read_students_choice == 1:  # READ STUDENT BY ID
                            student_id = input("Give student id: ")
                            student = students.find_by_id(student_id)
                            if student is None:
                                print(f"There is no student with id {student_id}")
                            else:
                                print(student)
                        elif read_students_choice == 2:  # READ ALL STUDENTS
                            for student in students.students:
                                print(student)
                                print(f"{20 * '='}")
                        elif read_students_choice == 3:  # BACK TO STUDENTS MENU
                            break
                elif manage_student_choice == 4:  # UPDATE STUDENTS
                    print("\nUPDATE STUDENTS")
                    print(f"{20 * '-'}")
                    update_student(students)
                elif manage_student_choice == 5:  # DELETE STUDENTS
                    print("\nDELETE STUDENTS")
                    print(f"{20 * '-'}")
                    delete_student(students)
                elif manage_student_choice == 6:  # BACK TO MAIN MENU
                    break

        elif choice == 2:
            while True:
                print("\nManage Teachers")
                print(f"{20 * '-'}")
                print("1. Create Teacher")
                print("2. Add Course to Teacher")
                print("3. Read Teachers")
                print("4. Update Teachers")
                print("5. Delete Teachers")
                print("6. Back to Main Menu")
                while True:
                    manage_teacher_choice = input("Pick one: ")
                    if not manage_teacher_choice.isdigit():
                        print("Give a number please")
                        continue
                    manage_teacher_choice = int(manage_teacher_choice)
                    if manage_teacher_choice < 1 or manage_teacher_choice > 6:
                        print("Index out of borders")
                    else:
                        break
                if manage_teacher_choice == 1:  # CREATE TEACHER
                    print("\nINSERT ΤΕΑCHER")
                    print(f"{20 * '-'}")
                    insert_teacher(teachers)
                elif manage_teacher_choice == 2:  # ADD COURSE TO TEACHER
                    print("\nADD COURSE TO TEACHER")
                    print(f"{20 * '-'}")
                    add_course_to_teacher(teachers, courses)
                elif manage_teacher_choice == 3:  # READ TEACHER
                    while True:
                        print("\nREAD TEACHERS")
                        print(f"{20 * '-'}")
                        print("1. Read a teacher by id")
                        print("2. Read all teachers")
                        print("3. Back to Teachers Menu")
                        while True:
                            read_teachers_choice = input("Pick one: ")
                            if not read_teachers_choice.isdigit():
                                print("Give a number please")
                                continue
                            read_teachers_choice = int(read_teachers_choice)
                            if read_teachers_choice < 1 or read_teachers_choice > 3:
                                print("Index out of borders")
                            else:
                                break
                        if read_teachers_choice == 1:  # READ TEACHER BY ID
                            teacher_id = input("Give teacher id: ")
                            teacher = teachers.find_by_id(teacher_id)
                            if teacher is None:
                                print(f"There is no student with id {teacher_id}")
                            else:
                                print(teacher)
                        elif read_teachers_choice == 2:  # READ ALL TEACHERS
                            for teacher in teachers.teachers:
                                print(teacher)
                                print(f"{20 * '='}")
                        elif read_teachers_choice == 3:  # BACK TO STUDENTS MENU
                            break
                elif manage_teacher_choice == 4:  # UPDATE TEACHER
                    print("\nUPDATE TEACHER")
                    print(f"{20 * '-'}")
                    update_teacher(teachers)
                elif manage_teacher_choice == 5:  # DELETE TEACHER
                    print("\nDELETE TEACHER")
                    print(f"{20 * '-'}")
                    delete_teacher(teachers)
                elif manage_teacher_choice == 6:  # BACK TO MAIN MENU
                    break

        elif choice == 3:
            while True:
                print("\nManage Course")
                print(f"{20 * '-'}")
                print("1. Create Course")
                print("2. Read Courses")
                print("3. Update Course")
                print("4. Delete Course")
                print("5. Back to Main Menu")
                while True:
                    manage_course_choice = input("Pick one: ")
                    if not manage_course_choice.isdigit():
                        print("Give a number please")
                        continue
                    manage_course_choice = int(manage_course_choice)
                    if choice < 1 or choice > 5:
                        print("Index out of borders")
                    else:
                        break
                if manage_course_choice == 1:
                    print("\nCREATE COURSE")
                    print(f"{20 * '-'}")
                    create_course(courses)
                elif manage_course_choice == 2:
                    while True:
                        print("\nREAD COURSES")
                        print(f"{20 * '-'}")
                        print("1. Read a course by id")
                        print("2. Read a course by title")
                        print("3. Read all courses")
                        print("4. Back to Courses Menu")
                        while True:
                            read_courses_choice = input("Pick one: ")
                            if not read_courses_choice.isdigit():
                                print("Give a number please")
                                continue
                            read_courses_choice = int(read_courses_choice)
                            if choice < 1 or choice > 4:
                                print("Index out of borders")
                            else:
                                break

                        if read_courses_choice == 1:  # read course by id
                            course_id = input("Give course id: ")
                            course = courses.find_by_id(course_id)
                            if course is None:
                                print(f"There is no course with id {course_id}")
                            else:
                                print(course)
                        elif read_courses_choice == 2:  # Read course by title
                            course_title = input("Give course title: ")
                            course = courses.find_by_title(course_title)
                            if course is None:
                                print(f"There is no course with title {course_title}")
                            else:
                                print(course)
                        elif read_courses_choice == 3:  # Read all courses
                            print("University Courses")
                            print(f"{20 * '-'}")
                            courses.print_courses()
                        elif read_courses_choice == 4:  # Go back to courses menu
                            break
                elif manage_course_choice == 3:  # UPDATE COURSE
                    print("\nUPDATE COURSE")
                    print(f"{20 * '-'}")
                    update_course(courses)
                elif manage_course_choice == 4:  # DELETE COURSE
                    print("\nDELETE COURSE")
                    print(f"{20 * '-'}")
                    delete_course(courses)
                elif manage_course_choice == 5:
                    break

        elif choice == 4:
            courses.store_to_file()
            teachers.store_to_file()
            students.store_to_file()
            print("Bye bye")
            break
Пример #2
0
def main():
    init_pupils_data()
    teachers = Teachers()

    while True:
        print("\n==============")
        print("      MENU      ")
        print("1 - Create Pupil")
        print("2 - Print")
        print("3 - Update Pupil")
        print("4 - Delete Pupil")
        print("5 - Create Teacher")
        print("6 - Read Teacher")
        print("7 - Update Teacher")
        print("8 - Delete Teacher")
        print("9 - Exit")
        choice = int(input("Pick one: "))

        if choice == 1:
            print("NEW PUPIL")
            print("=========")
            pupil = create_pupil()
            if pupil is None:
                continue
            else:
                print("NEW PUPIL")
                print_pupil(pupil)

        elif choice == 2:
            print("\n==============")
            print("    SUB MENU     ")
            print("1 - Print Pupil")
            print("2 - Print All Pupils (details)")
            print("3 - Print All Pupils (names)")
            print_choice = input("Pick one: ")
            if print_choice.strip().isdigit():
                print_choice = int(print_choice)
            else:
                print("Wrong input")
                continue

            if print_choice == 1:
                pupil_id = int(input("Type the pupil's id: "))
                pupil = search_pupil_by_id(pupil_id)
                if pupil is None:
                    print("Pupil does not exist with this id")
                else:
                    print("     PUPIL      ")
                    print_pupil(pupil)
            elif print_choice == 2:
                print_pupils_details()
            elif print_choice == 3:
                print_pupils_names()
            else:
                print("Wrong input")
                continue

        elif choice == 3:
            print("\n==============")
            print("      SUB-MENU (UPDATE)      ")
            print("1 - Update Pupil (search by id)")
            print("2 - Update Pupil (search by surname)")
            update_choice = input("Pick one: ")
            if update_choice.strip().isdigit():
                update_choice = int(update_choice)
            else:
                print("Wrong input")
                continue

            if update_choice == 1:
                pupil_id = int(input("Type an id: "))
                pupil = search_pupil_by_id(pupil_id)
                if pupil is None:
                    print("Error, there is no pupil with that id")
                    continue
            elif update_choice == 2:
                pupil_surname = input("Type the students surname: ")
                matching_pupils = search_pupil_by_surname(pupil_surname)
                if matching_pupils == []:
                    print("No match found")
                    continue
                if len(matching_pupils) == 1:
                    pupil = matching_pupils[0]
                else:
                    for p in matching_pupils:
                        print_pupil(p)
                        print(f"id = {p['id']}")
                        print("=" * 15)
                    pupil_id = int(input("type an id: "))
                    pupil = search_pupil_by_id(pupil_id)

            # pupil update

            pupil_update(pupil)

        elif choice == 4:
            print("\n==============")
            print("      SUB-MENU (DELETE)      ")
            print("1 - Delete Pupil (search by id)")
            print("2 - Delete Pupil (search by surname)")
            delete_choice = input("Pick one: ")
            if delete_choice.strip().isdigit():
                delete_choice = int(delete_choice)
            else:
                print("Wrong input")
                continue

            if delete_choice == 1:
                pupil_id = int(input("Type an id: "))
                pupil = search_pupil_by_id(pupil_id)
                if pupil is None:
                    print("Error, there is no pupil with that id")
                    continue
            elif delete_choice == 2:
                pupil_surname = input("Type the students surname: ")
                matching_pupils = search_pupil_by_surname(pupil_surname)
                if matching_pupils == []:
                    print("No match found")
                    continue
                if len(matching_pupils) == 1:
                    pupil = matching_pupils[0]
                else:
                    for p in matching_pupils:
                        print_pupil(p)
                        print(f"id = {p['id']}")
                        print("=" * 15)
                    pupil_id = int(input("type an id: "))
                    pupil = search_pupil_by_id(pupil_id)
            # Delete pupil
            delete_pupil_by_id(pupil["id"])
        elif choice == 5:
            first_name = input("Type teachers name: ")
            surname = input("Type teachers surname: ")
            teachers.create_teacher(first_name, surname)
        elif choice == 6:
            teacher_id = int(input("type the teacher's id: "))
            teacher = teachers.read_teacher(teacher_id)
            if teacher is None:
                print("No such teacher exists")
            else:
                teacher.print_teacher()
        elif choice == 7:
            teacher_id = int(input("type the teacher's id: "))
            teachers.update_teacher(teacher_id)
        elif choice == 8:
            teacher_id = int(input("type the teacher's id: "))
            teachers.delete_teacher(teacher_id)
        elif choice == 9:
            print("Bye")
            teachers.save_teachers_data()
            save_pupils_data()
            break
Пример #3
0
def main():

    init_pupils_data()
    teachers = Teachers()

    while True:
        print("\n===============")
        print("     MENU ")
        print("1 - Create Pupil")
        print("2 - Print")
        print("3 - Update Pupil")
        print("4 - Delete Pupil")
        print("5 - Create Teacher")
        print("6 - Read Teacher")
        print("7 - Update Teacher")
        print("8 - Delete Teacher")
        print("9 - Exit")
        choice = int(input("Pick one: "))

        if choice == 1:
            print("NEW PUPIL")
            print("===========")
            pupil = create_pupil()
            if pupil is None:
                continue
            else:
                print("NEW PUPIL")
                print_pupil(pupil)

        elif choice == 2:
            print("\n===============")
            print("     SUB-MENU (PRINT) ")
            print("1 - Print Pupil")
            print("2 - Print all pupils (details)")
            print("3 - Print all pupils (just the names)")
            print_choice = input("Give your choice: ")
            if print_choice.strip().isdigit():
                print_choice = int(print_choice)
            else:
                print("Wrong input!")
                continue

            if print_choice == 1:
                pupil_id = int(input("Give id: "))
                pupil = search_pupil_by_id(pupil_id)
                if pupil is None:
                    print("Pupil does not exist (with this id)")
                else:
                    print("   PUPIL   ")
                    print_pupil(pupil)

            elif print_choice == 2:
                print_pupils_details()
            elif print_choice == 3:
                print_pupils_names()
            else:
                print("Wrong input! ")
                continue

        elif choice == 3:
            print("\n===============")
            print("     SUB-MENU (UPDATE) ")
            print("1 - Update Pupil (search by id)")
            print("2 - Update Pupil (search by surname)")
            update_choice = input("Give your choice: ")
            if update_choice.strip().isdigit():
                update_choice = int(update_choice)
            else:
                print("Wrong input!")
                continue

            if update_choice == 1:
                pupil_id = int(input("Give id: "))
                pupil = search_pupil_by_id(pupil_id)
                if pupil is None:
                    print("Error! There is no pupil with this id!")
                    continue
            elif update_choice == 2:
                surname = input("Give surname: ")
                matching_pupils = search_pupil_by_surname(surname)
                if not matching_pupils:
                    print("No matching pupils with this surname!")
                    continue
                elif len(matching_pupils) == 1:
                    pupil = matching_pupils[0]
                else:
                    for p in matching_pupils:
                        print_pupil(p)
                        print(f"id = {p['id']}")
                        print("-" * 15)
                    pupil_id = int(input("Give id: "))
                    pupil = search_pupil_by_id(pupil_id)

            # pupil: update
            pupil_update(pupil)

        elif choice == 4:
            print("\n===============")
            print("     SUB-MENU (DELETE) ")
            print("1 - Delete Pupil (search by id)")
            print("2 - Delete Pupil (search by surname)")
            delete_choice = input("Give your choice: ")
            if delete_choice.strip().isdigit():
                delete_choice = int(delete_choice)
            else:
                print("Wrong input!")
                continue

            if delete_choice == 1:
                pupil_id = int(input("Give id: "))
                pupil = search_pupil_by_id(pupil_id)
                if pupil is None:
                    print("Error! There is no pupil with this id!")
                    continue
            elif delete_choice == 2:
                surname = input("Give surname: ")
                matching_pupils = search_pupil_by_surname(surname)
                if not matching_pupils:
                    print("No matching pupils with this surname!")
                    continue
                elif len(matching_pupils) == 1:
                    pupil = matching_pupils[0]
                else:
                    for p in matching_pupils:
                        print_pupil(p)
                        print(f"id = {p['id']}")
                        print("-" * 15)
                    pupil_id = int(input("Give id: "))
                    pupil = search_pupil_by_id(pupil_id)

            # pupil: delete
            delete_pupil_by_id(pupil["id"])
        elif choice == 5:
            first_name = input("Give name: ")
            surname = input("Give surname: ")
            teachers.create_teacher(first_name, surname)
        elif choice == 6:
            teacher_id = int(input("Give id: "))
            teacher = teachers.read_teacher(teacher_id)
            if teacher is None:
                print("No such teacher exists!")
            else:
                teacher.print_teacher()
        elif choice == 7:
            teacher_id = int(input("Give id: "))
            teachers.update_teacher(teacher_id)
        elif choice == 8:
            teacher_id = int(input("Give id: "))
            teachers.delete_teacher(teacher_id)
        elif choice == 9:
            print("Bye bye!")
            teachers.save_teachers_data()
            save_pupils_data()
            break
Пример #4
0
def main():

    pupils = Pupils()
    teachers = Teachers()
    lessons = Lessons()

    while True:
        print("\n===============")
        print("     MENU ")

        print("1 - Manage Pupils")
        print("2 - Manage Teachers")
        print("3 - Manage Lessons")
        print("4 - Exit")
        choice = int(input("Pick one: "))

        if choice == 1:
            print("\n===============")
            print(" PUPILS MENU ")

            print("1 - Create Pupil")
            print("2 - Print Pupil(s)")
            print("3 - Update Pupil")
            print("4 - Delete Pupil")
            pupils_choice = int(input("Pick one: "))

            if pupils_choice == 1:
                print("NEW PUPIL")
                print("===========")
                pupil = pupils.create_pupil()
                if pupil is None:
                    continue
                else:
                    print("NEW PUPIL")
                    print(pupil)

            elif pupils_choice == 2:
                print("\n===============")
                print("     SUB-MENU (PRINT) ")
                print("1 - Print Pupil")
                print("2 - Print all pupils (details)")
                print("3 - Print all pupils (just the names)")
                print_choice = input("Give your choice: ")
                if print_choice.strip().isdigit():
                    print_choice = int(print_choice)
                else:
                    print("Wrong input!")
                    continue

                if print_choice == 1:
                    pupil_id = int(input("Give id: "))
                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Pupil does not exist (with this id)")
                    else:
                        print("   PUPIL   ")
                        print(pupil)

                elif print_choice == 2:
                    print(pupils)
                elif print_choice == 3:
                    pupils.print_pupils_names()
                else:
                    print("Wrong input! ")
                    continue

            elif pupils_choice == 3:
                print("\n===============")
                print("     SUB-MENU (UPDATE) ")
                print("1 - Update Pupil (search by id)")
                print("2 - Update Pupil (search by surname)")
                update_choice = input("Give your choice: ")
                if update_choice.strip().isdigit():
                    update_choice = int(update_choice)
                else:
                    print("Wrong input!")
                    continue

                if update_choice == 1:
                    pupil_id = int(input("Give id: "))
                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Error! There is no pupil with this id!")
                        continue
                elif update_choice == 2:
                    surname = input("Give surname: ")
                    matching_pupils = pupils.search_pupil_by_surname(surname)
                    if not matching_pupils:
                        print("No matching pupils with this surname!")
                        continue
                    elif len(matching_pupils) == 1:
                        pupil = matching_pupils[0]
                    else:
                        for p in matching_pupils:
                            print(p)
                            print(f"id = {p['id']}")
                            print("-" * 15)
                        pupil_id = int(input("Give id: "))
                        pupil = pupils.search_pupil_by_id(pupil_id)

                # pupil: update
                pupils.pupil_update(pupil)

            elif pupils_choice == 4:
                print("\n===============")
                print("     SUB-MENU (DELETE) ")
                print("1 - Delete Pupil (search by id)")
                print("2 - Delete Pupil (search by surname)")
                delete_choice = input("Give your choice: ")
                if delete_choice.strip().isdigit():
                    delete_choice = int(delete_choice)
                else:
                    print("Wrong input!")
                    continue

                if delete_choice == 1:
                    pupil_id = int(input("Give id: "))
                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Error! There is no pupil with this id!")
                        continue
                elif delete_choice == 2:
                    surname = input("Give surname: ")
                    matching_pupils = pupils.search_pupil_by_surname(surname)
                    if not matching_pupils:
                        print("No matching pupils with this surname!")
                        continue
                    elif len(matching_pupils) == 1:
                        pupil = matching_pupils[0]
                    else:
                        for p in matching_pupils:
                            print(p)
                            print(f"id = {p['id']}")
                            print("-" * 15)
                        pupil_id = int(input("Give id: "))
                        pupil = pupils.search_pupil_by_id(pupil_id)

                # pupil: delete
                pupils.delete_pupil_by_id(pupil.pupil_id, lessons)

        elif choice == 2:
            print("\n===============")
            print(" TEACHERS MENU ")

            print("1 - Create Teacher")
            print("2 - Print Teacher(s)")
            print("3 - Update Teacher")
            print("4 - Delete Teacher")
            teacher_choice = int(input("Pick one: "))

            if teacher_choice == 1:
                first_name = input("Give name: ")
                surname = input("Give surname: ")
                teachers.create_teacher(first_name, surname)
            elif teacher_choice == 2:
                teacher_id = int(input("Give id: "))
                teacher = teachers.read_teacher(teacher_id)
                if teacher is None:
                    print("No such teacher exists!")
                else:
                    print(teacher)
            elif teacher_choice == 3:
                teacher_id = int(input("Give id: "))
                teachers.update_teacher(teacher_id)
            elif teacher_choice == 4:
                teacher_id = int(input("Give id: "))
                teachers.delete_teacher(teacher_id, lessons)

        elif choice == 3:
            print("\n===============")
            print(" LESSONS MENU ")

            print("1 - Create Lesson")
            print("2 - Print Lesson")
            print("3 - Update Lesson")
            print("4 - Delete Lesson")
            lesson_choice = int(input("Pick one: "))

            if lesson_choice == 1:
                lesson_name = input("Give lesson name: ")
                lessons.create_lesson(lesson_name)
            elif lesson_choice == 2:
                lesson_id = int(input("Give id: "))
                lesson = lessons.read_lesson(lesson_id)
                if lesson is None:
                    print("No such lesson exists!")
                else:
                    lesson.print_lesson_details(teachers, pupils)
            elif lesson_choice == 3:
                lesson_id = int(input("Give id: "))
                lessons.update_lesson(lesson_id, teachers, pupils)
            elif lesson_choice == 4:
                lesson_id = int(input("Give id: "))
                lessons.delete_lesson(lesson_id)

        elif choice == 4:
            print("Bye bye!")
            pupils.save_pupils_data()
            teachers.save_teachers_data()
            lessons.save_lessons_data()
            break
Пример #5
0
def main():

    pupils = Pupils()
    teachers = Teachers()
    lessons = Lessons()

    while True:

        menu()

        choice = get_int("Pick one: ")

        if choice == 1:

            pupils_menu()

            pupils_choice = get_int("Pick one: ")

            if pupils_choice == 1:
                print("NEW PUPIL")
                print("===========")
                pupil = pupils.create_pupil()
                if pupil is None:
                    continue
                else:
                    print("NEW PUPIL")
                    print(pupil)

            elif pupils_choice == 2:

                pupils_print_submenu()

                print_choice = get_int("Give your choice: ")

                if print_choice == 1:
                    pupil_id = get_int("Give id: ")
                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Pupil does not exist (with this id)")
                    else:
                        print("   PUPIL   ")
                        print(pupil)
                elif print_choice == 2:
                    print(pupils)
                elif print_choice == 3:
                    pupils.print_pupils_names()
                else:
                    print("Wrong input! ")
                    continue

            elif pupils_choice == 3:

                pupils_update_submenu()

                update_choice = get_int("Give your choice: ")
                if update_choice == 1:
                    pupil_id = get_int("Give id: ")
                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Error! There is no pupil with this id!")
                        continue
                elif update_choice == 2:
                    surname = input("Give surname: ")
                    matching_pupils = pupils.search_pupil_by_surname(surname)
                    if not matching_pupils:
                        print("No matching pupils with this surname!")
                        continue
                    elif len(matching_pupils) == 1:
                        pupil = matching_pupils[0]
                    else:
                        for p in matching_pupils:
                            print(p)
                            print(f"id = {p['id']}")
                            print("-" * 15)
                        pupil_id = get_int("Give id: ")
                        pupil = pupils.search_pupil_by_id(pupil_id)

                # pupil: update
                pupils.pupil_update(pupil)

            elif pupils_choice == 4:

                pupils_delete_submenu()

                delete_choice = get_int("Give your choice: ")

                if delete_choice == 1:
                    pupil_id = get_int("Give id: ")

                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Error! No pupil with this id!")
                        continue

                elif delete_choice == 2:
                    last_name = input("Give surname: ")
                    matching_pupils = pupils.search_pupil_by_surname(last_name)
                    if not matching_pupils:
                        print("No matching pupils with this surname!")
                        continue
                    elif len(matching_pupils) == 1:
                        pupil = matching_pupils[0]
                    else:
                        for p in matching_pupils:
                            print(p)
                            print(f"id = {p['id']}")
                            print("-" * 15)
                        pupil_id = get_int("Give id: ")
                        pupil = pupils.search_pupil_by_id(pupil_id)

                pupils.delete_pupil_by_id(pupil_id, lessons)

        elif choice == 2:

            teachers_menu()

            teacher_choice = get_int("Pick one: ")

            if teacher_choice == 1:
                first_name = input("Give name: ")
                last_name = input("Give surname: ")
                teachers.create_teacher(first_name, last_name)
            elif teacher_choice == 2:
                teacher_id = get_int("Give id: ")
                teacher = teachers.read_teacher(teacher_id)
                if teacher is None:
                    print("No such teacher exists!")
                else:
                    print(teacher)
            elif teacher_choice == 3:
                teacher_id = get_int("Give id: ")
                teachers.update_teacher(teacher_id)
            elif teacher_choice == 4:
                teacher_id = get_int("Give id: ")
                teachers.delete_teacher(teacher_id, lessons)

        elif choice == 3:

            lessons_menu()

            lesson_choice = get_int("Pick one: ")

            if lesson_choice == 1:
                lesson_name = input("Give lesson name: ")
                lessons.create_lesson(lesson_name)
            elif lesson_choice == 2:
                lesson_id = get_int("Give id: ")
                lesson = lessons.read_lesson(lesson_id)
                if lesson is None:
                    print("No such lesson exists!")
                else:
                    lesson.print_lesson_details(teachers, pupils)
            elif lesson_choice == 3:
                lesson_id = get_int("Give id: ")
                lessons.update_lesson(lesson_id, teachers, pupils)
            elif lesson_choice == 4:
                lesson_id = get_int("Give id: ")
                lessons.delete_lesson(lesson_id)

        elif choice == 4:
            print("Bye bye!")
            pupils.save_pupils_data()
            teachers.save_teachers_data()
            lessons.save_lessons_data()
            break
Пример #6
0
def main():
    pupils = Pupils()
    teachers = Teachers()
    lessons = Lessons()

    while True:
        print("\n==============")
        print("      MENU      ")
        print("1 - Manage Pupils")
        print("2 - Manage Teachers")
        print("3 - Manage Lessons")
        print("4 - Exit")
        choice = int(input("Pick a number: "))
        if choice == 1:
            print("\n==============")
            print(" PUPILS MENU ")
            print("1 - Create Pupil")
            print("2 - Print Pupil(s)")
            print("3 - Update Pupil")
            print("4 - Delete Pupil")
            choice = int(input("Pick one: "))

            if choice == 1:
                print("NEW PUPIL")
                print("=========")
                pupil = pupils.create_pupil()
                if pupil is None:
                    continue
                else:
                    print("NEW PUPIL")
                    print(pupil)

            elif choice == 2:
                print("\n==============")
                print("    SUB MENU     ")
                print("1 - Print Pupil")
                print("2 - Print All Pupils (details)")
                print("3 - Print All Pupils (names)")
                print_choice = input("Pick one: ")
                if print_choice.strip().isdigit():
                    print_choice = int(print_choice)
                else:
                    print("Wrong input")
                    continue

                if print_choice == 1:
                    pupil_id = int(input("Type the pupil's id: "))
                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Pupil does not exist with this id")
                    else:
                        print("     PUPIL      ")
                        print(pupil)
                elif print_choice == 2:
                    print(pupils)
                elif print_choice == 3:
                    pupils.print_pupils_names()
                else:
                    print("Wrong input")
                    continue

            elif choice == 3:
                print("\n==============")
                print("      SUB-MENU (UPDATE)      ")
                print("1 - Update Pupil (search by id)")
                print("2 - Update Pupil (search by surname)")
                update_choice = input("Pick one: ")
                if update_choice.strip().isdigit():
                    update_choice = int(update_choice)
                else:
                    print("Wrong input")
                    continue

                if update_choice == 1:
                    pupil_id = int(input("Type an id: "))
                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Error, there is no pupil with that id")
                        continue
                elif update_choice == 2:
                    pupil_surname = input("Type the students surname: ")
                    matching_pupils = pupils.search_pupil_by_surname(
                        pupil_surname)
                    if not matching_pupils:
                        print("No match found")
                        continue
                    if len(matching_pupils) == 1:
                        pupil = matching_pupils[0]
                    else:
                        for p in matching_pupils:
                            print(p)
                            print(f"id = {p['id']}")
                            print("=" * 15)
                        pupil_id = int(input("type an id: "))
                        pupil = pupils.search_pupil_by_id(pupil_id)

                # pupil update

                pupils.pupil_update(pupil)

            elif choice == 4:
                print("\n==============")
                print("      SUB-MENU (DELETE)      ")
                print("1 - Delete Pupil (search by id)")
                print("2 - Delete Pupil (search by surname)")
                delete_choice = input("Pick one: ")
                if delete_choice.strip().isdigit():
                    delete_choice = int(delete_choice)
                else:
                    print("Wrong input")
                    continue

                if delete_choice == 1:
                    pupil_id = int(input("Type an id: "))
                    pupil = pupils.search_pupil_by_id(pupil_id)
                    if pupil is None:
                        print("Error, there is no pupil with that id")
                        continue
                elif delete_choice == 2:
                    pupil_surname = input("Type the students surname: ")
                    matching_pupils = pupils.search_pupil_by_surname(
                        pupil_surname)
                    if not matching_pupils:
                        print("No match found")
                        continue
                    if len(matching_pupils) == 1:
                        pupil = matching_pupils[0]
                    else:
                        for p in matching_pupils:
                            print(p)
                            print(f"id = {p['id']}")
                            print("=" * 15)
                        pupil_id = int(input("type an id: "))
                        pupil = pupils.search_pupil_by_id(pupil_id)
                # Delete pupil
                pupils.delete_pupil_by_id(pupil.pupil_id, lessons)
        elif choice == 2:
            print(" TEACHER MENU ")
            print("1 - Create Teacher")
            print("2 - Print Teacher")
            print("3 - Update Teacher")
            print("4 - Delete Teacher")
            choice = int(input("Pick one: "))
            if choice == 1:
                first_name = input("Type teachers name: ")
                surname = input("Type teachers surname: ")
                teachers.create_teacher(first_name, surname)
            elif choice == 2:
                teacher_id = int(input("type the teacher's id: "))
                teacher = teachers.read_teacher(teacher_id)
                if teacher is None:
                    print("No such teacher exists")
                else:
                    teacher.print_teacher()
            elif choice == 3:
                teacher_id = int(input("type the teacher's id: "))
                teachers.update_teacher(teacher_id)
            elif choice == 4:
                teacher_id = int(input("type the teacher's id: "))
                teachers.delete_teacher(teacher_id, lessons)
        elif choice == 3:
            print(" LESSONS MENU ")
            print("1 - Create Lesson")
            print("2 - Print Lesson")
            print("3 - Update Lesson")
            print("4 - Delete Lesson")
            choice = int(input("Pick one: "))
            if choice == 1:
                lesson_name = input("Type lesson's name: ")
                lessons.create_lesson(lesson_name)
            elif choice == 2:
                lesson_id = int(input("type the lesson's id: "))
                lesson = lessons.read_lesson(lesson_id)
                if lesson is None:
                    print("No such lesson exists")
                else:
                    lesson.print_lesson_details(teachers, pupils)
            elif choice == 3:
                lesson_id = int(input("Type lesson's id: "))
                lessons.update_lesson(lesson_id, teachers, pupils)
            elif choice == 4:
                lesson_id = int(input("Type lesson's id: "))
                lessons.delete_lesson(lesson_id)
        elif choice == 4:
            print("Bye")
            teachers.save_teachers_data()
            pupils.save_pupils_data()
            lessons.save_lessons_data()
            break