93.4k views
3 votes
Write a function that takes 2 strings as its parameters, with one of them being a single character and the other a sentence. The function should return the number of times that character is found within the sentence. The function is case sensitive.

User Dotnetnoob
by
6.0k points

1 Answer

0 votes

Answer:

Written in Python:

def strings2(str1,str2):

count = str1.count(str2)

print("The count is:", count)

Step-by-step explanation:

This line defines the function

def strings2(str1,str2):

The line counts the number occurrence of the substring (str2) in the main string (str1)

count = str1.count(str2)

This line prints the number of occurence

print("The count is:", count)

User Gregor Petrin
by
5.7k points