- #!/usr/bin/python
-
-
- import os
- import sys
- #to use the join function
- from string import *
- #to generate random int
- import random
-
-
- #if mode set to check,ask to enter 17 digits
- #TODO
-
- #if we re on windows(sic) , display result on notepad(otherwise they wont be able to copy/paste them)
- if sys.platform=="win32":
- try:
- output=open("results","w")
- except:
- print "cant write output file,output only on screen :)"
-
-
-
- #default mode,generate a ean...
- #else generate
-
- for w in range(10):
-
- num=""
- i=1
- while i <= 17:
- num += str(random.randint(1,9))
- i +=1
-
-
- result=0
- t=1
-
- for i in num:
- if t%2==1:
- result += 3*int(i)
- else:
- result += int(i)
- t += 1
-
-
- #get rest from arrondi
-
- if result%10==0:
- rest=0
- else:
- rest=10 -result%10
-
-
-
- # if we are on windows and output was well created,output there...
- if sys.platform=="win32" and output:
- output.write(str(num)+str(rest)+"\n")
-
- else:
- print str(num)+str(rest)
-
-
-
-
- #if we are on windows and output was well created,display output
- if sys.platform=="win32" and output:
- output.close()
- os.system("notepad results")
- # then kill it
- os.remove("results")
-
-
-
-
-
#!/usr/bin/python
import os
import sys
#to use the join function
from string import *
#to generate random int
import random
#if mode set to check,ask to enter 17 digits
#TODO
#if we re on windows(sic) , display result on notepad(otherwise they wont be able to copy/paste them)
if sys.platform=="win32":
try:
output=open("results","w")
except:
print "cant write output file,output only on screen :)"
#default mode,generate a ean...
#else generate
for w in range(10):
num=""
i=1
while i <= 17:
num += str(random.randint(1,9))
i +=1
result=0
t=1
for i in num:
if t%2==1:
result += 3*int(i)
else:
result += int(i)
t += 1
#get rest from arrondi
if result%10==0:
rest=0
else:
rest=10 -result%10
# if we are on windows and output was well created,output there...
if sys.platform=="win32" and output:
output.write(str(num)+str(rest)+"\n")
else:
print str(num)+str(rest)
#if we are on windows and output was well created,display output
if sys.platform=="win32" and output:
output.close()
os.system("notepad results")
# then kill it
os.remove("results")