I'm trying to create a program which outputs how many times a specific character was used.
For example, if the sentence is I like bikes!
The output should be:
I = 1
l = 1
i = 2
k = 2
e = 2
b = 1
s = 1
! = 1
However my program does this
I = 1
l = 1
i = 2
k = 1
e = 2
b = 1
i = 2
k = 2
e = 2
s = 1
! = 1
So its doubling up the letters.
def count_char(text):
for char in text:
count = text.count(char)
print(char + ' = ' + str(count))
How can I fix this?