PW Akshay

Generation

generate functionFri, 02 Dec 2022

Read a text file and display the number of vowels/consonants/uppercase/lowercase characters in the file

def read_file_and_display_stat(file_name): with open(file_name, "r") as input_file: content = input_file.read() num_vow = 0 num_cons = 0 num_upper = 0 num_lower = 0 for char in content: if char in "aeiouAEIOU": num_vow += 1 elif char.isalpha(): num_cons += 1 elif char.islower(): num_lower += 1 elif char.isupper(): num_upper += 1 print("Number of vowels: " + str(num_vow)) print("Number of consonants: " + str(num_cons)) print("Number of uppercase letters: " + str(num_upper)) print("Number of lowercase letters: " + str(num_lower)) read_file_and_display_stat("functions_and_files.txt")

Questions about programming?Chat with your personal AI assistant