def count_words_chars_lines(text):
    word_count = len(text.split())
    char_count = len(text)
    line_count = text.count('\n') + 1
    return word_count, char_count, line_count

def main():
    while True:
        choice = input("Enter 'T' to input text, 'F' to input file, or 'Q' to quit: ").upper()

        if choice == 'T':
            text = input("Enter your text: ")
            word_count, char_count, line_count = count_words_chars_lines(text)
            print(f"Words: {word_count}, Characters: {char_count}, Lines: {line_count}")

        elif choice == 'F':
            try:
                file_name = input("Enter the file name: ")
                with open(file_name, 'r') as file:
                    text = file.read()
                    word_count, char_count, line_count = count_words_chars_lines(text)
                    print(f"Words: {word_count}, Characters: {char_count}, Lines: {line_count}")
            except FileNotFoundError:
                print("File not found. Please try again.")
            except Exception as e:
                print(f"An error occurred: {e}")

        elif choice == 'Q':
            print("Exiting...")
            break

        else:
            print("Invalid choice. Please try again.")

if __name__ == "__main__":
    main()