I am trying to make a program that reads from a "integers.txt" file which contains:
1
2
3
4
11
13
15
16
18
20
33
39
42
48
50
51
and finds all the even numbers in "integers.txt" and writes them to a new file "evens.txt"
then finds all the odd numbers in "integers.txt" and does the same.
So far I have:
#sieve
import sys
def open_read(file_name, mode):
try:
the_file = open(file_name, mode)
except(IOError):
print "Unable to open file", file_name
sys.exit()
else:
return the_file
def write_evens():
even_file = open("evens.txt", "w")
the_file = open_read("integers.txt", "r")
for num in the_file:
num = int(num)
if num % 2 == 0:
even_file.write(num)
def main():
write_evens()
main()
raw_input("\n\nPress enter to exit.")
I can't figure out what this error that it creates means, or how to get around it. Maybe I am approaching the program wrong....any ideas?