Computer Science, asked by Sonu7016, 9 months ago

write a function in python to display total no of lines starting with an alphabet t also display the count no of vowels , consonants,uppercase and lowercase character in same file

Answers

Answered by eklavyajain3456
1

In this program, our task is to count the total number of vowels and consonants present in the given string. As we know that, The characters a, e, i, o, u are known as vowels in the English alphabet. Any character other than that is known as the consonant. To solve this problem, First of all, we need to convert every upper-case character in the string to lower-case so that the comparisons can be done with the lower-case vowels only not upper-case vowels, i.e.(A, E, I, O, U). Then, we have to traverse the string using a for or while loop and match each character with all the vowels, i.e., a, e, I, o, u. If the match is found, increase the value of count by 1 otherwise continue with the normal flow of the program. The algorithm of the program is given below.

Algorithm

Define a string.

Convert the string to lower case so that comparisons can be reduced. Else we need to compare with capital (A, E, I, O, U).

If any character in string matches with vowels (a, e, i, o, u ) then increment the vcount by 1.

If any character lies between 'a' and 'z' except vowels, then increment the count for ccount by 1.

Print both the counts.

vcount = 0;  

ccount = 0;  

str = "This is a really simple sentence";  

   

#Converting entire string to lower case to reduce the comparisons  

str = str.lower();  

for i in range(0,len(str)):    

   #Checks whether a character is a vowel  

   if str[i] in ('a',"e","i","o","u"):  

       vcount = vcount + 1;  

   elif (str[i] >= 'a' and str[i] <= 'z'):  

       ccount = ccount + 1;  

print("Total number of vowel and consonant are" );  

print(vcount);  

print(ccount);  

Output:

Number of vowels: 10

Number of consonants: 17

Answered by amuthamcablevkl
2

Answer:

def Count(str):  

   upper, lower,  consonant , vowels = 0, 0, 0, 0

   for i in range(len(str)):  

       if str[i].isupper():  

        elif str[i].islower():  

           lower += 1

if (ch == 'a' or ch == 'e' or ch == 'i'  

                       or ch == 'o' or ch == 'u'):  

               vowels += 1

           else:  

               consonant += 1

         

   print('Upper case letters:', upper)  

print(' vowels no’, vowels)

print('  consonant no’,  consonant)

  print('Lower case letters:', lower)  

     

Explanation:

plz mark me as brainest

Similar questions