Character Count
Easy+10 XP · +5 Aurastringscountingloops
Rohan is learning about strings and wants to count how many times a specific character appears in a message. He has a message, and he wants to know the count of a particular character within it. Can you help him write a program to find this out?
Input
Two lines of input: The first line contains the message (a string). The second line contains the character to count (a single character string).
Output
A single integer: the number of times the character appears in the message.
Constraints
The message will contain only lowercase English letters. The character to count will be a single lowercase English letter. The length of the message is between 1 and 1000.
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
programming r
Output
2
The character 'r' appears 2 times in 'programming'.
Example 2
Input
hello world l
Output
3
The character 'l' appears 3 times in 'hello world'.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
programming r
Example 2 input
hello world l