Advertisement
boris-vlasenko

111335 Статистика по файлу

Mar 24th, 2016
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import string
  2.  
  3. F = open('input.txt', 'r')
  4. words = 0
  5. letters = 0
  6. text = F.readlines()
  7. lines = len(text)
  8.  
  9. for line in text:
  10.     w = ''
  11.     for s in line.strip()+' ':
  12.         if s in string.ascii_letters:
  13.             letters += 1
  14.             w += s                     
  15.         if  s in " '-.,!?" and w:
  16.             words += 1
  17.             #print(w)
  18.             w = ''
  19.  
  20.            
  21.      
  22. print("""Input file contains:
  23. """+str(letters)+""" letters
  24. """+str(words)+""" words
  25. """+str(lines)+""" lines""")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement