Count Character
Python
Easy
3 views
Problem Description
A string s is provided and a character ch is provided. Count how many times ch occurs in s.
Input Format
Line1: s. Line2: ch (single char).
Output Format
One integer count.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines: sys.exit(0)
s=lines[0]
ch=(lines[1] if len(lines)>1 else '')
ch=ch[0] if ch else ''
c=0
for x in s:
if x==ch:
c+=1
sys.stdout.write(str(c))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!