Advertisement
Guest User

Untitled

a guest
May 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #!/usr/bin/python
  2. from time import time, sleep
  3. from random import randint
  4. from numpy import random as r
  5.  
  6. RUTS = ['19.470.140-3',
  7. '20.067.784-k',
  8. '10.481.357-7',
  9. '11.624.369-5',
  10. '15.753.502-1',
  11. '19.124.836-8',
  12. '19.154.575-5',
  13. '15.324.128-k',
  14. '17.684.932-5',
  15. '12.789.123-0']
  16.  
  17. def load_ruts():
  18. ruts = []
  19. try:
  20. with open('ruts.txt') as f:
  21. for line in f:
  22. # para omitir comentarios!
  23. if "#" in line:
  24. continue
  25. ruts.append(line.strip())
  26. except:
  27. with open('ruts.txt', 'w') as f:
  28. f.write("# importante seguir el formato!")
  29. for rut in RUTS:
  30. f.write(rut + '\n')
  31. ruts = RUTS
  32. return ruts
  33.  
  34. RUTS = load_ruts()
  35.  
  36. def get_random():
  37. return RUTS[randint(0, len(RUTS) - 1)]
  38.  
  39. def generate_rut():
  40. start = '{:,}'.format(randint(1000000, 25000000)).replace(',', '.')
  41. end = r.choice(map(str, range(0, 10)) + ['k'])
  42. return start + '-' + end
  43.  
  44. def limpiar(texto):
  45. return texto.replace('.','').replace('-k','10').replace('-','0')
  46.  
  47. if __name__ == "__main__":
  48. diff = raw_input('generar rut o conocidos (1 o 2): ')
  49. if diff == '1':
  50. func = generate_rut
  51. else:
  52. func = get_random
  53.  
  54. # Cantidad de ruts a ingresar
  55. Q = 10
  56.  
  57. n = Q
  58. for i in range(1,4):
  59. print(4-i)
  60. sleep(1)
  61.  
  62. print("ahora!")
  63. choice = get_random()
  64. start = time()
  65. while n != 0:
  66.  
  67. print("Escribe '%s'" % choice)
  68. t = str(raw_input())
  69. if t.strip() != limpiar(choice):
  70. print("\nerror, escribir de nuevo\n")
  71. continue
  72. else:
  73. print("\nfaltan %d veces\n" % n - 1)
  74. n -= 1
  75. choice = func()
  76. end = time()
  77. print("Tardaste %f segundos" % (end - start))
  78.  
  79. user = raw_input('ingresa nombre: ')
  80. with open('results.csv', 'a') as f:
  81. f.write('{0};{1};{2}\n'.format(user, end - start, Q))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement