Skip to content

Commit a026983

Browse files
committed
Day 8: Calculate lower and upper alphabet count
1 parent 9ebe345 commit a026983

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

daily_challenges/day_8/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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}\nNo. of Lower case Characters : {lower}"
23+
24+
25+
print(calculate_alpha_case('Hello Mr. Rogers, how are you this fine Tuesday?'))

daily_challenges/day_8/practice.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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'

0 commit comments

Comments
 (0)