Q.No.2 - Write a python program that takes a sentence as input and displays the number of words, number of capital letter, number of small letter and number of special symbols in the inputted sentence.

Sol.-

a=input("Enter ")
word=alpha=num=capi=small=special=space=0
for i in range(len(a)):
    if a[i].isalpha() :
        alpha=alpha+1
        if a[i].islower() :
            small=small+1
        else:
            capi+=1
    elif a[i].isdigit() :
        num=num+1
    elif a[i]==" ":
        space=space+1
    else :
        special+=1
print("Lenght of alphabets ",alpha)
print("Lenght of digit",num)
print("Lenght of small letter",small)
print("Lenght of Capital letter", capi)
print("Lenght of Special", special)
print("Lenght of Word", len(a))


Explain : Step 1: Create a variable in which user input store. Step 2: Now create variable and assign them 0. Step 3: Start a for loop which depend on length of input string. Step 4: if a[i] is alpha mean character then the alpha value increase by 1 and in this a nested condition. If alpha true then condtion activate and check the letter is samll or capital Step 5: If a[i] is digit then it increase num value. Step 6: We use for space so it does not affect the value of special character value. Step 7: At last any word/letter remain will be treated as special character and store in specail. Step 8: We just print the values.

OUTPUT: