mraps98

Python_countCharOccurenceInFile

May 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def countChar(text,char):
  2.     count = int()
  3.     for c in text:
  4.         if c == char:
  5.             count += 1
  6.     return count
  7.  
  8. filename = input("Enter file to analyze: ")
  9. char = input("What character do you want to count?: ")
  10.  
  11. with open(filename, 'r') as fi:
  12.     text = fi.read()
  13.     print(countChar(text,char))
Add Comment
Please, Sign In to add comment