Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from string import ascii_letters, ascii_lowercase, ascii_uppercase
- def count_characters(stream):
- no_small = 0
- no_block = 0
- no_special = 0
- no_vowel = 0
- no_consonant = 0
- no_numbers = 0
- for lines in stream:
- for word in lines:
- if word in ascii_letters :
- if word in ascii_uppercase : no_block += 1
- if word in ascii_lowercase : no_small += 1
- if word.lower() in ("a","e","i","o","u") : no_vowel += 1
- if word.lower() not in ("a","e","i","o","u") : no_consonant += 1
- elif ord("0") <= ord(word) <= ord("9") : no_numbers += 1
- else : no_special += 1
- return no_small, no_block, no_special, no_vowel, no_consonant, no_numbers
- def main():
- filename = input("Please Enter the Path of the File : ") #Enter the full File path (/home/usr/Documents/file1.dat)
- filetype = input("Is it a Text File (Y/n) : ")
- try :
- if filetype.lower() == "y" : file = open(filename)
- elif filetype.lower() == "n" : file = open(filename, "rb")
- else : print("Invalid Choice\nExiting...")
- data = file.readlines()
- no_small, no_block, no_special, no_vowel, no_consonant, no_numbers = count_characters(data)
- print("\nThe File Contains\nNo. of Small Letters : ", no_small)
- print("No. of BLOCK Letters : ", no_block)
- print("No. of Vowels : ", no_vowel)
- print("No. of Consonants : ", no_consonant)
- print("No. of Numbers : ", no_numbers)
- print("No. of Special Characters : ", no_special)
- except FileNotFoundError : print("Oops!!! Such a File does not Exists...")
- main()
Add Comment
Please, Sign In to add comment