0% found this document useful (0 votes)
8 views

Practical Assignment 29

Uploaded by

Tahir Pirjade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Practical Assignment 29

Uploaded by

Tahir Pirjade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Roll No : 58

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:

with open(file_path, 'r') as file:

content = file.read()
for char in content:

if char.isalpha():

if char in vowels:

total_vowels += 1

elif char in consonants:

total_consonants += 1

if char.isupper():

total_uppercase += 1

elif char.islower():

total_lowercase += 1

else:

total_other += 1

except FileNotFoundError:

print(f"Error: File '{file_path}' not found.")

return

print(f"Total Vowels in file: {total_vowels}")

print(f"Total Consonants in file: {total_consonants}")

print(f"Total Capital letters in file: {total_uppercase}")

print(f"Total Small letters in file: {total_lowercase}")

print(f"Total Other than letters: {total_other}")

# Provide the path to your file

file_path = 'your_file.txt' # Replace with the actual file path


# Call the function with the file path

count_characters(file_path)

 OUTPUT : -

You might also like