Computer Science, asked by 004tranquil, 9 months ago

read a text file and display the number of vowels/consonants/uppercase/lowercase characters in the file in python hints(word.isupper(),word.islower(),if loop to count vowels and consonants ,file.read())

Answers

Answered by PrateekGupta12
67

Answer:

fileName = input("Enter the file to check: ").strip()

infile = open(fileName, "r")

vowels = set("A E I O U a e i o u")

cons = set("b c d f g h j k l m n p q r s t v w x y z B C D F G H J K L M N P Q R S T V W X Y Z")

text = infile.read().split()

 

countV = 0

for V in text:

   if V in vowels:

       countV += 1

countC = 0

for C in text:

   if C in cons:

       countC += 1

print("The number of Vowels is: ",countV,"\nThe number of consonants is: ",countC)

Explanation:

Wasn't that easy.

Answered by shilpa85475
2

Explanation:

fileName = input("Enter the file to check: ").strip()

infile = open(fileName, "r")

vowels = set("A E I O U a e i o u")

cons = set("b c d f g h j k l m n p q r s t v w x y z B C D F G H J K L M N P Q R S T V W X Y Z")

text = infile.read().split()

countV = 0

for V in text:

   if V in vowels:

       countV += 1

countC = 0

for C in text:

if C in cons:  

      countC += 1

print("The number of Vowels is: ",countV,"\nThe number of consonants is: ",countC)

The vowels are a,e,i,o,u

and the remaining letters are the consonants.

The file here consists of all such letters.

The program is to display only the vowels and consonants in both lower and upper cases alphabets.

Similar questions