Python function not running, interpreter not giving any errors
<p>I'm very new to Python and having a problem with a program I'm doing for a class.  main() and create_file work, but when it gets to read_file, the interpreter just sits there.  The program is running but nothing is happening.</p>

<p>The answer is probably something very simple, but I just can't see it.  Thanks in advance for any help.</p>

<p>I'm using IDLE (Python and IDLE v. 3.5.2)</p>

<p>Here's the code:</p>

<pre><code>import random

FILENAME = "randomNumbers.txt"

def create_file(userNum):

    #Create and open the randomNumbers.txt file
    randomOutput = open(FILENAME, 'w')

    #Generate random numbers and write them to the file
    for num in range(userNum):
        num = random.randint(1, 500)
        randomOutput.write(str(num) + '\n')

    #Confirm data written
    print("Data written to file.")

    #Close the file
    randomOutput.close()

def read_file():

    #Open the random number file
    randomInput = open(FILENAME, 'r')

    #Declare variables
    entry = randomInput.readline()
    count = 0
    total = 0

    #Check for eof, read in data, and add it
    while entry != '':
        num = int(entry)
        total += num
        count += 1

    #Print the total and the number of random numbers
    print("The total is:", total)
    print("The number of random numbers generated and added is:", count)

    #Close the file
    randomInput.close()

def main():

    #Get user data
    numGenerate = int(input("Enter the number of random numbers to generate: "))

    #Call create_file function
    create_file(numGenerate)

    #Call read_file function
    read_file()

main()
</code></pre>

<p>You have an infinite <code>while</code> loop in the function, since <code>entry</code> never changes during the loop.</p>

<p>The Pythonic way to process all the lines in a file is like this:</p>

<pre><code>for entry in randomInput:
    num = int(entry)
    total += num
    count += 1
</code></pre>

python function