import os
def count_words_chars_lines(text):
    words = text.split()
    num_words = len(words)
    num_chars = len(text)
    num_lines = text.count('\n') + 1  # Adding 1 for the last line which might not end with a newline character
    return num_words, num_chars, num_lines

def main():
    while True:
        print("Enter '1' to input text directly.")
        print("Enter '2' to read text from a file.")
        print("Enter '3' to exit.")
        choice = input("Choose an option: ")

        if choice == '1':
            input_text = input("Enter the text: ")
            num_words, num_chars, num_lines = count_words_chars_lines(input_text)
            print(f"Number of words: {num_words}")
            print(f"Number of characters: {num_chars}")
            print(f"Number of lines: {num_lines}")
        elif choice == '2':
            file_name = input("Enter the file name: ")
            if os.path.exists(file_name):
                with open(file_name, 'r') as file:
                    file_text = file.read()
                num_words, num_chars, num_lines = count_words_chars_lines(file_text)
                print(f"Number of words: {num_words}")
                print(f"Number of characters: {num_chars}")
                print(f"Number of lines: {num_lines}")
            else:
                print("File not found.")
        elif choice == '3':
            print("Exiting...")
            break
        else:
            print("Invalid choice.")

if __name__ == "__main__":
    main()