Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

This still isn't working, for my blood drive program. Any ideas? It gives me a syntax error.

the writeToFile function
def writeToFile(averagePints, pints):
   outFile = open('blood.txt', 'a')
   print outFile,('Pints Each Hour')
   counter = 0
   while counter < 7:
          outFile.write(str(pints[counter]) + '\n')
          counter = counter + 1

   outFile.write('Average Pints')
   outFile.write(str(averagePints) + '\n\n')
   outFile.close()

2 Answers

The syntax error is coming from the line: print outFile,('Pints Each Hour') All arguments to print need to be inside the parentheses, and if you are specifying a file it needs to be with the keyword argument file=, otherwise it will be considered something to print out to the console.

Well, that seems to make sense but other than the = sign. The instructions state that it is supposed to be typed like so:

print >> outFile, 'Pints Each Hour'

I tried that, it results in an error, so I tried all of these, one by one:

print >> outFile, "Pints Each Hour"
print >> outFile, ('Pints Each Hour')
print >> outFile, ("Pints Each Hour")
print outFile, 'Pints Each Hour'
print outFile, "Pints Each Hour"
print outFile, ('Pints Each Hour')
print outFile, ("Pints Each Hour")
print outFIle., 'Pints Each Hour'

I'm sure I tried other things as well but none have worked. If the instructions stated that it was supposed to be typed as the initial statement at the top, then do you know why it won't work?