Python writing to a new file each new loop
Question: I'm trying to use a while loop to write to a series of new files. Each
iteration of the loop should write to a new file, and close it before the next
loop begins. I'm using Python 2.7, and I'd like to resolve this without having
to install any additional libraries if possible.

I've gotten the program to work for writing to a single file, but once I try
to use the loop, the program loops indefinitely, writing over and over to the
initial file. It isn't closing the first file and moving to the next loop.
Here's the code:

_Update: The problem has been resolved. I moved everything in the while loop
to a separate function, and just called it repeatedly in the while loop while
incrementing the chapter value of the argument. Also made sure to account for
lower case p in the arrow brackets as well as upper case P. Thanks everyone
for the help!_

    
    
    import urllib
    
    storyID = raw_input("Please Enter Story ID: ")
    chapters = raw_input("Please Enter the number of Chapters: ")
    countDown = int(chapters)
    countUp = 1
    
    while countUp <= countDown :
    
        storyURL = "https:website/" + storyID + "/" + str(countUp) + "/"
        f = urllib.urlopen(storyURL)
    
        with open ('chapter' + str(countUp) + '.html', 'a') as g:
    
            bof = False
            eof = False
    
    
            while eof == False :
                line = f.readline()
                if "<P>" in line and bof == False :
                    bof = True
                    g.write("""<html>\n<meta charset='utf-8'>\n
                    <META NAME='ROBOTS' CONTENT='NOARCHIVE'>\n
                    <META http-equiv='X-UA-Compatible' content='IE=edge'>\n
                    <META NAME='format-detection' content='telephone=no'>\n
                    <META NAME='viewport' content='width=device-width'>\n
                    <meta name="google-translate-customization" content="6babbc5ad0624c76-e1cef323edf23c09-g0466c4b8ae39c7a2-12">\n""")
                    g.write(line)
    
                elif "Chapter Navigation" in line and bof == True:
                    eof = True
                    g.write ("</html>")
    
                elif bof == True :
                    g.write(line)
        g.close()
        countUp = countUp + 1
    


Answer: Case matters.

    
    
    countUp = countUp + 1
    

Better yet:

    
    
    countUp += 1
    

