Monday, 8 February 2021

Practical No. 6: WAP in Python to read a text file and print the number of uppercase and lowercase letters in the file.

 













'''
Practical No. 6: WAP in Python to read a text file and print the number of
uppercase and lowercase letters in the file
'''
f=open("Vowel.txt","r")
data=f.read()
U=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R', \
   'S','T','U','V','W','X','Y','Z',]
L=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r', \
   's','t','u','v','w','x','y','z']

cu=0
cl=0
for i in data:
    if i in U:
        cu=cu+1
    elif i in L:
        cl=cl+1

ct=0
for i in data:
    ct=ct+1
print("Number of Uppercase letters in the file=",cu)
print("Number of Lowercase Letters in the file=",cl)
print("Number of Total Chars in the file=",ct)


f.close()







'''
Practical No. 6: WAP in Python to read a text file and print the number of
uppercase and lowercase letters in the file
'''
f=open("Vowel.txt","r")
data=f.read()


cu=0
cl=0
for i in data:
    if i.isupper():
        cu=cu+1
    elif i.islower():
        cl=cl+1

ct=0
for i in data:
    ct=ct+1
print("Number of Uppercase letters in the file=",cu)
print("Number of Lowercase Letters in the file=",cl)
print("Number of Total Chars in the file=",ct)


f.close()


No comments:

Post a Comment