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("\n--- Simple Word Counter ---")
        print("1. Enter text")
        print("2. Read from a file")
        print("3. Exit")
        choice = input("Choose an option (1/2/3): ")

        if choice == '1':
            text = input("Enter the text:\n")
            words, chars, lines = count_words_chars_lines(text)
            print(f"\nWords: {words}\nCharacters: {chars}\nLines: {lines}")

        elif choice == '2':
            filename = input("Enter the file path: ")
            if not os.path.exists(filename):
                print("File not found.")
                continue
            with open(filename, 'r') as file:
                text = file.read()
                words, chars, lines = count_words_chars_lines(text)
                print(f"\nWords: {words}\nCharacters: {chars}\nLines: {lines}")

        elif choice == '3':
            print("Exiting program.")
            break

        else:
            print("Invalid choice. Please enter a valid option.")

if name == "__main__":
    main()