Computer Science, asked by AparnaJiji17, 6 months ago

write a python program to read a file and display the number of vowels, consonants, uppercase, lowercase characters in a file​

Answers

Answered by valeriy69
2

import string

vowels = ["a", "e", "i", "o", "u"]

upper_vowels = [x.upper() for x in vowels]

alphabets = string.ascii_lowercase

upper_alphabets = [x.upper() for x in alphabets]

consonants = [x for x in alphabets if x not in vowels]

upper_consonants = [x.upper() for x in consonants]

vowel_counter = 0

consonant_counter = 0

uppercase_counter = 0

lowercase_counter = 0

with open("test.txt") as f:

for line in f:

for char in line:

if char in vowels or char in upper_vowels:

vowel_counter += 1

if char in consonants or char in upper_consonants:

consonant_counter += 1

if char in upper_alphabets:

uppercase_counter += 1

if char in alphabets:

lowercase_counter += 1

print(f"vowels: {vowel_counter}\nconsonants: {consonant_counter}\nuppercase: {uppercase_counter}\nlowercase: {lowercase_counter}")

\small\mathsf\color{lightgreen}useful?\: \color{white}\mapsto\: \color{orange}brainliest

Similar questions