[ create a new paste ] login | about

Link: http://codepad.org/qLGcq5h2    [ raw code | output | fork | 1 comment ]

Python, pasted on Nov 26:
def main():
    endProgram = 'no'
    print
    while endProgram == 'no':
        option = 0
print
print('Enter 1 to enter in new data and store to file')
print('Enter 2 to display data from the file')
option = input('Enter now ->')
option = int(option)
print

pints = [0] * 7
totalPints = getTotal(Pints)
averagePints = getAverage(totalPints)
if option == 1:
    pints = getPints(pints)
    totalPints = getTotal(pints)
    averagePints = getAverage(totalPints)
    writeToFile(averagePints, pints)
if option == 2:
    readFromFile()
else:
    endProgram = input('Do you want to end program? (Enter no or yes): ')
while not (endProgram == 'yes' or endProgram == 'no'):
    print ('Please enter a yes or no')
    endProgram = input('Do you want to end program? (Enter no or yes): ')

def getPints(pints):
    counter = 0
    while counter < 7:
        numEntered = input('Enter pints collected: ')
        pints[counter] = int(numEntered)
        counter = counter + 1
    return pints

def getTotal(pints):
    totalPints = 0
    counter = 0
    while counter < 7:
        totalPints = totalPints + pints[counter]
        counter = counter + 1
    return totalPints

def getAverage(totalPints):
    averagePints = float(totalPints) / 7
    return averagePints

def writeToFile(averagePints, pints):
    outFile = open('blood.txt', 'a')
    outFile.write('Pints Each Hour' + "\n")
    outFile.write(str(pints[counter]) + '\n')
    counter = counter + 1
    outFile.write(str(averagePints) + '\n\n')
    outFile.close()

def readFromFile():
    inFile = open('blood.txt', 'r')
    for line in inFile:
        print (line)
main()


Output:
1
2
3
4
5
6
7

Enter 1 to enter in new data and store to file
Enter 2 to display data from the file
Enter now ->Traceback (most recent call last):
  Line 9, in <module>
    option = input('Enter now ->')
EOFError


Create a new paste based on this one


Comments:
posted by Carter895 on Nov 26
Need Help Getting this to run smoothly, I don't know why it's throwing up an error for my defined modules when it's run, such as getTotal, since it should be reading from it. So anything that gets this up and running in the manner intended would be appreciated.
reply