[Tutor] Pease help
Glen Chan
gchan401 at msn.com
Sat Jun 7 01:00:01 CEST 2014
Hello I am a student trying to figure out this program. Here is my objective and program below. What am I doing wrong? I can't get this to work.
Calculate the average pints of
blood donated during a blood drive. The
program should take in the number of pints donated during the drive, based on a
seven hour drive period. The average
pints donated during that period should be calculated and written to a
file. Write a loop around the program to
run multiple times. The data should be
appended to the file to keep track of multiple days. If the user wants to print data from the
file, read it in and then display it.
Store the pints per hour and the average pints donated in a file called
blood.txt.
#the
main function
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 ->')
print
# declare variables
pints = [0] * 7
totalPints = 0
averagePints = 0
if option == 1:
# function calls
pints = getPints(pints)
totalPints = getTotal(pints, totalPints)
averagePints = getAverage(totalPints,
averagePints)
else:
endProgram = raw_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 = raw_input('Do you want to
end program? (Enter no or yes): ')
#the
getPints function
def
getPints(pints):
counter = 0
while counter < 7:
pints[counter] = input('Enter pints
collected: ')
counter = counter + 1
return pints
#the
getTotal function
def
getTotal(pints, totalPints):
counter = 0
while counter < 7:
totalPints = totalPints + pints[counter]
counter = counter + 1
return totalPints
#the
getAverage function
def
getAverage(totalPints, averagePints):
averagePints = float(totalPints) / 7
return averagePints
#the
writeToFile function
def
writeToFile(averagePints, pints):
#the
readFromFile function
def readFromFile(averagePints, pints):
#
calls main
main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140606/d6751408/attachment-0001.html>
More information about the Tutor
mailing list