import os

def count_stats(text):
    lines = text.split('\n')
    words = text.split()
    characters = len(text)
    return len(lines), len(words), characters

def read_text_from_input():
    text = input("Enter your text (press Enter to finish):\n")
    return text

def read_text_from_file(filename):
    try:
        with open(filename, 'r') as file:
            return file.read()
    except FileNotFoundError:
        print("File not found.")
        return None
    except Exception as e:
        print("An error occurred:", e)
        return None

def main():
    while True:
        print("\nOptions:")
        print("1. Enter text manually")
        print("2. Read text from a file")
        print("3. Exit")
        choice = input("Choose an option: ")

        if choice == '1':
            text = read_text_from_input()
            if text:
                lines, words, characters = count_stats(text)
                print("Lines:", lines)
                print("Words:", words)
                print("Characters:", characters)

        elif choice == '2':
            filename = input("Enter the filename: ")
            text = read_text_from_file(filename)
            if text:
                lines, words, characters = count_stats(text)
                print("Lines:", lines)
                print("Words:", words)
                print("Characters:", characters)

        elif choice == '3':
            print("Exiting program.")
            break

        else:
            print("Invalid choice. Please try again.")

if __name__ == "__main__":
    main()

