

def count_words_characters_lines(text):
    num_words = len(text.split())
    num_characters = len(text)
    num_lines = text.count('\n') + 1
    return num_words, num_characters, num_lines

def main():
    while True:
        print("Enter '1' to input a text, '2' to read from a file, or '0' to exit:")
        choice = input("Choice: ")

        if choice == '0':
            print("Exiting the program...")
            break
        elif choice == '1':
            text = input("Enter the text: ")
            num_words, num_characters, num_lines = count_words_characters_lines(text)
            print(f"Number of words: {num_words}")
            print(f"Number of characters: {num_characters}")
            print(f"Number of lines: {num_lines}")
        elif choice == '2':
            file_name = input("Enter the file name: ")
            try:
                with open(file_name, 'r') as file:
                    text = file.read()
                    num_words, num_characters, num_lines = count_words_characters_lines(text)
                    print(f"Number of words: {num_words}")
                    print(f"Number of characters: {num_characters}")
                    print(f"Number of lines: {num_lines}")
            except FileNotFoundError:
                print("File not found. Please try again.")
        else:
            print("Invalid choice. Please try again.")

if __name__ == '__main__':
    main()        
            


