iHerzeleid

Mar 4, 2008, 11:15 PM

how can i get the list to print out like this (to a output file)

ex input: 10

2

5

def get_factor(x):

l = []

for i in range(1,((x + 2)/2)):

if (x%i == 0 and i!=1 and i!=x):

l = l +[i]

return l

m = input ("Please enter a number greater than 2: ")

outfile = 'primes-'+str(m)+'.txt'

output = open (outfile, "w")

nn = get_factor(m)

nnn = (str(nn[1:]))

#for i in range(len(nnn)):

print "Found", len(get_factor(m)), "Numbers; please check the file primes-",m,".txt"

print nn

output.write (nnn)

output.close()

ex input: 10

2

5

def get_factor(x):

l = []

for i in range(1,((x + 2)/2)):

if (x%i == 0 and i!=1 and i!=x):

l = l +[i]

return l

m = input ("Please enter a number greater than 2: ")

outfile = 'primes-'+str(m)+'.txt'

output = open (outfile, "w")

nn = get_factor(m)

nnn = (str(nn[1:]))

#for i in range(len(nnn)):

print "Found", len(get_factor(m)), "Numbers; please check the file primes-",m,".txt"

print nn

output.write (nnn)

output.close()