I have to write a table called tempconv.txt, the table should have temps from -300-212 fah and the cel equivalents with steps of 10 or 20, presented in 2 columns.I keep getting a syntax error. I think i am having trouble with the opening and closing of the file. Thanks for any help.

def feh():
    outfile = open("tempconv.txt","w")
    outfile.write ("%10s%10s\n"%(feh,"cel"))
for i in range ( -300,240,120):
                   counterCelsius = (i -32) / 1.8
                   outfile.write("%10.3f %10.3f\n" %(i,convertCelsius)
    outfile.close (

I am still getting a systex error when closing the file

We can't really guess what that is. Post the entire error message. As a general rule, check that line of code and the previous for the same number of open and closing parens. If there is a paren error on the previous line, the interpreter sees the next line as a continuation line. Also, you close the file, but never open it, so that could be one of the errors.

what is the easy way

Pseudocode:

with open(...) as myfile:
     generator -> formatter -> join the line -> join the lines -> myfile.write argument

Edited 6 Years Ago by pyTony: n/a

This question has already been answered. Start a new discussion instead.