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
    return num_words, num_chars, num_lines

def main():
    while True:
        print("\nEnter '1' to input text manually.")
        print("Enter '2' to input a file path.")
        print("Enter '3' to exit.")

        choice = input("Enter your choice: ")

        if choice == '1':
            text = input("\nEnter the text: ")
            num_words, num_chars, num_lines = count_words_chars_lines(text)
            print("\nNumber of words:", num_words)
            print("Number of characters:", num_chars)
            print("Number of lines:", num_lines)
        elif choice == '2':
            file_path = input("\nEnter the file path: ")
            if not os.path.isfile(file_path):
                print("Error: Invalid file path.")
                continue
            with open(file_path, 'r') as file:
                text = file.read()
                num_words, num_chars, num_lines = count_words_chars_lines(text)
                print("\nNumber of words:", num_words)
                print("Number of characters:", num_chars)
                print("Number of lines:", num_lines)
        elif choice == '3':
            print("\nExiting the program. Goodbye!")
            break
        else:
            print("Error: Invalid choice. Please enter a valid option.")

if __name__ == "__main__":
    main()
