File tree 3 files changed +44
-0
lines changed
3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Write a Python function that accepts a string and calculates the number of upper case letters
3
+ and lower case letters.
4
+
5
+ Sample String : 'Hello Mr. Rogers, how are you this fine Tuesday?'
6
+ Expected Output :
7
+ No. of Upper case characters : 4
8
+ No. of Lower case Characters : 33
9
+ """
10
+
11
+
12
+ def calculate_alpha_case (input_string ):
13
+ upper = 0
14
+ lower = 0
15
+
16
+ for item in input_string :
17
+ if item .isupper ():
18
+ upper += 1
19
+ elif item .islower ():
20
+ lower += 1
21
+
22
+ return f"No. of Upper case characters : { upper } \n No. of Lower case Characters : { lower } "
23
+
24
+
25
+ print (calculate_alpha_case ('Hello Mr. Rogers, how are you this fine Tuesday?' ))
Original file line number Diff line number Diff line change
1
+ import re
2
+
3
+
4
+ def upper_lower_count (string ):
5
+ lower_count , upper_count = 0 , 0
6
+ x = re .findall ("[a-zA-z]" , string )
7
+ for i in range (0 , len (x )):
8
+ if x [i ] == x [i ].lower ():
9
+ lower_count = lower_count + 1
10
+ else :
11
+ upper_count = upper_count + 1
12
+ return f"Count of upper case chars is { upper_count } , and count of lower case chars is { lower_count } "
13
+
14
+
15
+ # testing the fn.
16
+ str_test_1 = 'Hello Mr. Rogers, how are you this fine Tuesday?'
17
+ upper_lower_count (str_test_1 )
18
+ # output
19
+ 'Count of upper case chars is 4, and count of lower case chars is 33'
You can’t perform that action at this time.
0 commit comments