Guest User

Chapter 11

a guest
Sep 29th, 2012
409
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Exercise 11.1
  2. #import re
  3. #fhand = open('mbox.txt')
  4.  
  5. #count = 0
  6.  
  7. #expression = raw_input('Enter a regular expression: ')
  8.  
  9. #for line in fhand:
  10. # line = line.rstrip()
  11. # if re.search(expression, line) :
  12. # count = count + 1
  13. #count = str(count)
  14. #print 'mbox.txt had ' + count + ' lines that matched ' + expression
  15.  
  16. #Exercise 11.2
  17.  
  18. import re
  19.  
  20. file = raw_input('Enter file: ')
  21.  
  22. fhand = open (file)
  23. x = 0
  24. y = 0
  25. total = 0
  26. count = 0
  27. for line in fhand:
  28. line = line.rstrip()
  29. x = re.findall('New Revision: ([0-9]+)', line)
  30. if len (x) > 0:
  31. count = count + 1
  32. for y in x:
  33. y = float(y)
  34. total = total + y
  35.  
  36. average = total/count
  37.  
  38. print average
RAW Paste Data