example 1:-
def string_test(str):
d={"UPPER_CASE":0, "LOWER_CASE":0}
for c in str:
if c.isupper():
d["UPPER_CASE"]+=1
elif c.islower():
d["LOWER_CASE"]+=1
else:
pass
print ("Original String : ", str)
print ("No. of Upper case characters : ", d["UPPER_CASE"])
print ("No. of Lower case Characters : ", d["LOWER_CASE"])
string_test('BlockChain')
output:-
Original String : BlockChain
No. of Upper case characters : 2
No. of Lower case Characters : 8
>>>
example 2:-
def up_low(s):
u = sum(1 for i in s if i.isupper())
l = sum(1 for i in s if i.islower())
print( "No. of Upper case characters : %s,No. of Lower case characters : %s" % (u,l))
up_low("Hello Mr. Rogers, how are you this fine Tuesday?")
output:-
No. of Upper case characters : 2,No. of Lower case characters : 8
>>>
example 3:-
string = input ("Enter String : ")
upp = low = 0
for letter in string :
if ord(letter) in range (65,91):
upp = upp + 1
elif ord(letter) in range (97,123):
low = low + 1
print("upper-case letter are : ",upp,"\nlower-case letter are : ",low)
output:-
Enter String : BlockChain
upper-case letter are : 2
lower-case letter are : 8
>>>
Post a Comment
If you have any doubts, Please let me know
Thanks!