Write a program in python to display all the consonant in the user input.
E.g. user input: Hello Good Day to you.
Output:
consonant H = 1
consonant l = 2
consonant G = 1
consonant d = 1
consonant D = 1
etc
PYTHON PROGRAM ===>
from collections import OrderedDict
def remove_duplicate(str1):
return "".join(OrderedDict.fromkeys(str1))
sentence = input("Enter : ")
newsentence = remove_duplicate(sentence) # create new string from
sentence after remove duplicate character
for ch in newsentence:
if(ch=='B' or ch=='b' or ch=='C' or ch =='c' or ch=='D' or ch=='d'
or ch=='F' or ch=='f' or ch=='G' or ch=='g' or ch=='H' or ch=='h'
or ch== 'J' or ch=='j' or ch=='K' or ch =='k' or ch=='L' or ch=='l'
or ch=='M' or ch=='m' or ch=='n' or ch=='N' or ch=="P" or ch=="p"
or ch=='Q' or ch=='q' or ch=='R' or ch =='r' or ch=='S' or ch=='s'
or ch=='T' or ch=='t' or ch=='V' or ch=='v' or ch=="W" or ch=="w"
or ch=='X' or ch=='x' or ch=='Y' or ch =='y' or ch=='Z' or
ch=='z'):
count =0
for x in sentence :
if(ch==x):
count= count+1
print("consonent ",ch," = ",count)
CODE SCREENSHOT ====>
OUTPUT SCREENSHOT ===>
UPDATED CODE ===>
sentence = input("Enter : ")
newsentence = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz" # a
string contains all consonant in uppercase and lowercase
for ch in newsentence:
if(ch=='B' or ch=='b' or ch=='C' or ch =='c' or ch=='D' or ch=='d'
or ch=='F' or ch=='f' or ch=='G' or ch=='g' or ch=='H' or ch=='h'
or ch== 'J' or ch=='j' or ch=='K' or ch =='k' or ch=='L' or ch=='l'
or ch=='M' or ch=='m' or ch=='n' or ch=='N' or ch=="P" or ch=="p"
or ch=='Q' or ch=='q' or ch=='R' or ch =='r' or ch=='S' or ch=='s'
or ch=='T' or ch=='t' or ch=='V' or ch=='v' or ch=="W" or ch=="w"
or ch=='X' or ch=='x' or ch=='Y' or ch =='y' or ch=='Z' or
ch=='z'):
count =0
for x in sentence :
if(ch==x):
count= count+1
print("consonant ",ch," = ",count)
OUTPUT ===>
Get Answers For Free
Most questions answered within 1 hours.