# -*- coding: utf-8 -*-
"""Simple Project (2nd)-Khalid AlHarbi

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1UxdYtliwDhiW1oaovPq9q_B7VYOPDNCk
"""

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:
        try:
            choice = input("Enter '1' to input text manually or '2' to read from a file, or 'exit' to quit: ")
            if choice == '1':
                input_text = input("Enter your text: ")
                words, chars, lines = count_words_chars_lines(input_text)
                print(f"Number of words: {words}")
                print(f"Number of characters (including spaces): {chars}")
                print(f"Number of lines: {lines}")
            elif choice == '2':
                file_name = input("Enter the file name: ")
                with open(file_name, 'r') as file:
                    file_text = file.read()
                words, chars, lines = count_words_chars_lines(file_text)
                print(f"Number of words: {words}")
                print(f"Number of characters (including spaces): {chars}")
                print(f"Number of lines: {lines}")
            elif choice.lower() == 'exit':
                break
            else:
                print("Invalid choice. Please enter '1', '2', or 'exit'.")
        except FileNotFoundError:
            print("File not found. Please enter a valid file name.")
        except Exception as e:
            print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()