from typing import List

def add_mountain(names: List[str], heights: List[int]) -> None:
    """Add a new mountain entry if it doesn't already exist."""
    name = input("Name des Berges: ").strip()
    if name in names:
        print("Schon vorhanden.")
        return

    try:
        height = int(input("Höhe: ").strip())
    except ValueError:
        print("Ungültige Eingabe! Bitte eine Zahl angeben.")
        return

    names.append(name)
    heights.append(height)
    print(f"'{name}' mit {height} m wurde hinzugefügt.")


def display_mountains(names: List[str], heights: List[int]) -> None:
    """Print the list of all mountains and their heights."""
    print("\nBergliste:")
    for name, height in zip(names, heights):
        print(f"  • {name}: {height} m")


def get_highest_mountain(names: List[str], heights: List[int]) -> tuple[str, int]:
    """Return the highest mountain as (name, height)."""
    max_height = max(heights)
    index = heights.index(max_height)
    return names[index], max_height


def calculate_average_height(heights: List[int]) -> float:
    """Return the average height of all mountains."""
    return sum(heights) / len(heights)


def count_3000ers(heights: List[int]) -> int:
    """Return how many mountains are 3000 meters or higher."""
    return sum(h >= 3000 for h in heights)


def main() -> None:
    """Main program loop."""
    print("Berge Österreich")

    mountain_names = ["Großglockner", "Wildspitze", "Weißkugel", "Großvenediger"]
    mountain_heights = [3798, 3768, 3738, 3657]

    while True:
        choice = input("Neue Eingabe (j/n)? ").strip().lower()
        if choice == "j":
            add_mountain(mountain_names, mountain_heights)
        elif choice == "n":
            break
        else:
            print("Bitte nur 'j' oder 'n' eingeben.")

    display_mountains(mountain_names, mountain_heights)

    highest_name, highest_height = get_highest_mountain(mountain_names, mountain_heights)
    print(f"\nDer höchste Berg ist der {highest_name} mit {highest_height} m.")

    avg_height = calculate_average_height(mountain_heights)
    print(f"Die durchschnittliche Höhe beträgt {avg_height:.1f} m.")

    count = count_3000ers(mountain_heights)
    print(f"In der Liste sind {count} 3000er gespeichert.")


if __name__ == "__main__":
    main()
