import os

def count_words_chars_lines(text):
    num_words = len(text.split())
    num_chars = len(text)
    num_lines = text.count('\n') + 1
    return num_words, num_chars, num_lines

def main():
    while True:
        print("Choose an option:")
        print("1. Input text manually")
        print("2. Read from a file")
        print("3. Exit")

        choice = input("Enter your choice (1/2/3): ")

        if choice == '1':
            user_input = input("Enter your text: ")
            words, chars, lines = count_words_chars_lines(user_input)
            print(f"Number of words: {words}")
            print(f"Number of characters: {chars}")
            print(f"Number of lines: {lines}")

        elif choice == '2':
            filename = input("Enter the filename: ")
            if os.path.exists(filename):
                with open(filename, 'r') as file:
                    file_text = file.read()
                    words, chars, lines = count_words_chars_lines(file_text)
                    print(f"Number of words: {words}")
                    print(f"Number of characters: {chars}")
                    print(f"Number of lines: {lines}")
            else:
                print("File not found. Please enter a valid filename.")

        elif choice == '3':
            print("Exiting the program...")
            break

        else:
            print("Invalid choice. Please enter 1, 2, or 3.")

if __name__ == "__main__":
    main()