Please send questions to
st10@humboldt.edu .
# contract: writeSquares: number string -> void
# purpose: write the first <howMany> squares (starting
# with 1 squared) into a file <whereToPutThem>
# NOTE: if <whereToPutThem> currently exists
# when this is called, ITS PREVIOUS CONTENTS WILL
# BE DELETED
# example: if I call writeSquares(5, "looky.txt"), then
# looky.txt will contain (ignoring the comment marks)
#1
#4
#9
#16
#25
def writeSquares(howMany, whereToPutThem):
myFileObject = open(whereToPutThem, "w")
ct = 1
while ct <= howMany:
myFileObject.write( str( ct * ct ) + "\n" )
ct = ct + 1
myFileObject.close()