Advertisement
Guest User

Untitled

a guest
Nov 12th, 2013
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. Exercise 11.1
  2. # -*- coding: iso-8859-15  -*-
  3. import re
  4. total=0
  5. fasa=open('/home/fer/mbox.txt')
  6. clave=str(raw_input('Que queremos buscar? '))
  7. for linea in fasa:
  8.     x = re.findall(clave, linea)
  9.     if len(x) > 0:
  10.         total +=1
  11. print 'Encontre la clave %s %d veces'% (clave,  total)
  12.  
  13. Exercise 11.2
  14. # -*- coding: iso-8859-15  -*-
  15. import re
  16. media=float()
  17. count=int()
  18. total= float()
  19. fname = raw_input('Nombre de archivo ')
  20. try:
  21.     fasa=open(fname)
  22.     for linea in fasa:
  23.         if re.search('^New Revision:\s[0-9]',  linea):
  24.             x = re.findall('^New Revision:\s([0-9]+)', linea)
  25.             total = total + float(x[0])
  26.             count +=1
  27.     media = (total / count)
  28.     print 'La media es %d'% (media)
  29. except:
  30.     print 'nombre de archivo invalido'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement