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' + "

" ) outFile . write ( str ( pints [ counter ]) + '

' ) counter = counter + 1 outFile . write ( str ( averagePints ) + '



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