Skip to content

Capital Letter Counter Created by devzohaib #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions 2022-Oct/02 Oct 2022/dev_zohaib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def count_capital_letters(s: str) -> int:
"""
Problem Statement: Accept a String from user & Calculate Capital Letters from it
input: "Hello World"
output: 2
>>> count_capital_letters('Hello World')
:param s:
:return: int
"""
count = 0
for i in s:
if i.isupper():
count += 1
return count


# one liner solution
def count_capital_letters_oneLiner(s: str) -> int:
return sum(1 for c in s if c.isupper())


# driver code
if __name__ == '__main__':
s = input('Enter a string: ')
print(f'Number of capital letters in {s} is {count_capital_letters(s)}')
# print(f'Number of capital letters in {s} is {count_capital_letters_oneLiner(s)}')