def count(text):
    word = text.split()
    num_word = len(word)
    num_le = sum(len(words) for words in word)
    num_lin = text.count('\n') + 1
    num_spa = text.count(' ')
    return num_word,num_le,num_lin,num_spa

def m ():
    while True:
        print("\nWord Counter")
        print("1. enter text manually  ")
        print("2. read text from a file ")
        print("3. exit")
        choisce = input("enter your choisce (1/2/3) : ")
        
        if choisce == '1' :
            text = input("enter the text :\n")
            num_word,num_le,num_lin,num_spa = count(text)
            print(f"\nnumber of worsd : {num_word}")
            print(f" number of characters : {num_le}")
            print(f" number of lines : {num_lin}")
            print(f" number of spaces : {num_spa}")
         
        elif choisce == '2':
            file_name = input("enter the file name :")
            try:
                with open(file_name,'r') as file :
                 text = file.read()
                 num_word,num_le,num_lin,num_spa = count(text)
                 print(f"\nNumber of words: {num_word}")
                 print(f"Number of characters: {num_le}")
                 print(f"Number of lines: {num_lin}")
                 print(f"Number of spaces : {num_spa}")
            except FileNotFoundError:
                print("file not found. Please enter a valid file name.")
        elif choisce == '3':
            print("exiting..")
            break
        else:
            print("Invalid choice. Please enter 1, 2, or 3.")
if __name__ == "__main__":
    m()
                
                

    
    
    
    















    















    
    



    























