Загрузка данных


students = {}

def add_student():
    name = input("ФИО студента: ").strip()
    if name in students:
        print("Студент уже существует.")
        return
    students[name] = []
    print(f"Студент '{name}' добавлен.")

def add_grade():
    name = input("ФИО студента: ").strip()
    if name not in students:
        print("Студент не найден.")
        return
    try:
        grade = int(input("Оценка (2-5): "))
        if grade < 2 or grade > 5:
            print("Оценка должна быть от 2 до 5.")
            return
        students[name].append(grade)
        print("Оценка добавлена.")
    except ValueError:
        print("Введите целое число.")

def show_students():
    if not students:
        print("Студентов нет.")
        return
    for name, grades in students.items():
        print(f"  {name}: {grades if grades else 'оценок нет'}")

def show_grades():
    name = input("ФИО студента: ").strip()
    if name not in students:
        print("Студент не найден.")
        return
    grades = students[name]
    print(f"{name}: {grades if grades else 'оценок пока нет'}")

def average_grade():
    name = input("ФИО студента: ").strip()
    if name not in students:
        print("Студент не найден.")
        return
    grades = students[name]
    if not grades:
        print("Нет оценок для подсчёта среднего.")
        return
    print(f"Средний балл {name}: {sum(grades)/len(grades):.2f}")

def top_student():
    eligible = {n: g for n, g in students.items() if g}
    if not eligible:
        print("Ни у кого нет оценок.")
        return
    best = max(eligible, key=lambda n: sum(eligible[n]) / len(eligible[n]))
    avg = sum(eligible[best]) / len(eligible[best])
    print(f"Лучший студент: {best}, средний балл: {avg:.2f}")

def failing_students():
    found = [n for n, g in students.items() if 2 in g]
    if not found:
        print("Студентов с оценкой 2 нет.")
    else:
        print("Студенты с оценкой 2: " + ", ".join(found))

while True:
    print("\n1. Добавить студента  2. Добавить оценку  3. Список студентов  4. Оценки студента")
    print("5. Средний балл  6. Лучший студент  7. Двоечники  0. Выйти")
    choice = input("Выбор: ").strip()
    if choice == "1": add_student()
    elif choice == "2": add_grade()
    elif choice == "3": show_students()
    elif choice == "4": show_grades()
    elif choice == "5": average_grade()
    elif choice == "6": top_student()
    elif choice == "7": failing_students()
    elif choice == "0":
        print("До свидания!")
        break
    else:
        print("Неверный пункт меню.")