![Python-courses-python-exercises-games-Python-courses-](https://1.bp.blogspot.com/-T3BongcoJFo/X4CftQxVL8I/AAAAAAAAB5U/Lf59WgNyhGo2FdogKqxv0PIy_Ef7XDPdgCLcBGAsYHQ/s0/my-python-courses-python-exercises-with-solutions.png)
Exercise 49
Write a Python program as a function that counts the number of times a character appears in a string without using any predefined functions.
Solution
def caracter_count(s , c):
# initializing counter
counter = 0
for x in s:
if c == x:
counter = counter + 1
return counter
# Testing function
s = "python programming"
print("The number of times of appearance of character 'n' in 's' is = " ,caracter_count(s , 'n'))
# The output is : The number of times of appearance of character 'n' in 's' is = 2
Younes Derfoufi
my-courses.net
my-courses.net
Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have. word counter