string - how to count repeated characters in text file using python -
i beginner in python , trying make small program in python count repeated character in text file
here code
import string def count_char(text,char): count = 0 c in text: if c == char: count +=1 return count filename = raw_input("enter file name:") open(filename) f: text=f.read() print(count_char(text,"r"))
but prints output as
>> 0
please tell me wrong code ?
move return outside of loop. it's going through 1 iteration.
Comments
Post a Comment