Write a function that finds the number of occurrences of a s
Write a function that finds the number of occurrences of a specified character in a string using the following header:
def count(s, ch):
The str class has the count method. Implement your method without using the count method. For example, count(“system error, syntax error”, “error”) returns 2. Write a test program that prompts the user to enter two strings and displays the number of occurrences of the second string in the first string. Needs to be written in python 3 please.
Solution
Function to find substring in the given string is as follows. This funtion finds all overlapped occurrences.
def count(s,ch):
 s = s.lower()
 ch = ch.lower()
 l = len(ch)
 ct = 0
 for c in range(0,len(s)):
 if s[c:c+l] == ch:
 ct += 1
 print (\"\'\" + ch + \"\' occureed in \'\" + s + \"\' \" + str(ct) + \" times.\")
text = raw_input(\"Enter String: \")
 pattern = raw_input(\"Enter petten to be search: \")
 count(text,pattern)

