diff --git a/1 File handle/File handle text/question 5.py b/1 File handle/File handle text/question 5.py index b41373135cf..795433266aa 100644 --- a/1 File handle/File handle text/question 5.py +++ b/1 File handle/File handle text/question 5.py @@ -1,20 +1,52 @@ """Write a function in python to count the number of lowercase alphabets present in a text file “happy.txt""" +import time +import os + +print("You will see the count of lowercase, uppercase and total count of alphabets in provided file..") + + +file_path = input("Please, Enter file path: ") + +if os.path.exists(file_path): + print('The file exists and this is the path:\n',file_path) + + +def lowercase(file_path): + try: + + with open(file_path, 'r') as F: + # Define the initial count of the lower and upper case. + lowercase_count = 0 + uppercase_count = 0 + + value = F.read() + + for i in value: + if i.islower(): + # It will increase the count. + lowercase_count += 1 + elif i.isupper(): + uppercase_count += 1 + + + + total_count = lowercase_count+uppercase_count + + print("The total number of lower case letters are", lowercase_count) + time.sleep(1) + print("The total number of upper case letters are", uppercase_count) + time.sleep(1) + print("The total number of letters are", total_count) + time.sleep(1) + + except FileNotFoundError: + print("File is not exist.. Please check AGAIN") + + -def lowercase(): - with open("happy.txt") as F: - count_lower = 0 - count_upper = 0 - value = F.read() - for i in value: - if i.islower(): - count_lower += 1 - elif i.isupper(): - count_upper += 1 - print("The total number of lower case letters are", count_lower) - print("The total number of upper case letters are", count_upper) - print("The total number of letters are", count_lower + count_upper) if __name__ == "__main__": - lowercase() + + lowercase(file_path)