Practical Assignment 29
Practical Assignment 29
Assignment 29
Q. Write a Program to read the content of file and display the total
number of consonants, uppercase, vowels and lower case
characters‟
Out Put:
Total Vowels in file : 25
Total Consonants in file n : 35
Total Capital letters in file : 5
Total Small letters in file : 55
Total Other than letters : 0
Code : -
def count_characters(file_path):
vowels = "aeiouAEIOU"
consonants = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
total_vowels = 0
total_consonants = 0
total_uppercase = 0
total_lowercase = 0
total_other = 0
try:
content = file.read()
for char in content:
if char.isalpha():
if char in vowels:
total_vowels += 1
total_consonants += 1
if char.isupper():
total_uppercase += 1
elif char.islower():
total_lowercase += 1
else:
total_other += 1
except FileNotFoundError:
return
count_characters(file_path)
OUTPUT : -