Advertisement
fplanzer

rutgen

May 21st, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. def crear(t, nametxt):
  2.     rute = open(nametxt + ".txt", "a")
  3.     rute.write(t + "\n")
  4.     rute.close()
  5.  
  6.  
  7. def generarut(desde, hasta):
  8.  
  9.     arreglo = []
  10.  
  11.     for i in range(desde, hasta):
  12.         total = 0
  13.         multiplo = 2
  14.         rut = str(i)
  15.         for rinverso in reversed(rut):
  16.             total += int(rinverso) * multiplo
  17.  
  18.             if multiplo == 7:
  19.                 multiplo = 2
  20.             else:
  21.                 multiplo += 1
  22.  
  23.             modulus = total % 11
  24.             verificador = 11 - modulus
  25.  
  26.             if verificador == 10:
  27.                 div = "k"
  28.             elif verificador == 11:
  29.                 div = "0"
  30.             elif verificador < 10:
  31.                 div = verificador
  32.  
  33.         arreglo.append(rut + str(div))
  34.  
  35.     return arreglo
  36.  
  37. if "__main__" == __name__:
  38.  
  39. #       desde = input("ingresa rut inicial ej:12345678 =>>: ")
  40. #       hasta = input("ingresa rut final: ")
  41.         desde = xxxxxxxx
  42.         hasta = yyyyyyyy
  43.         nametxt = raw_input("ingresa nombre para archivo txt: ")
  44.  
  45.         for runs in generarut(desde, hasta):
  46. #               print (runs)
  47. #           crear(runs, nametxt)
  48.                 crear(runs, nametxt )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement