Program prints questions for user input, but won't show the answer output
MRAB
python at mrabarnett.plus.com
Wed May 18 21:31:43 EDT 2016
On 2016-05-19 02:04, Jake Kobs wrote:
> Here is the code:
>
> #Lab 9-4 Blood Drive
>
> #the main function
> def main():
> endProgram = 'no'
> while endProgram == 'no':
> print
> # declare variables
> pints = [0] * 7
> totalPints = 0
> averagePints = 0
> highPints = 0
> lowPints = 0
>
>
>
>
>
>
>
>
>
>
>
>
> # function calls
> pints = getPints(pints)
> totalPints = getTotal(pints, totalPints)
> averagePints = getAverage(totalPints, averagePints)
> highPints = getHigh(pints, highPints)
> lowPints = getLow(pints, lowPints)
> displayInfo(averagePints, highPints, lowPints)
>
> 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 = totalPints / 7
> return averagePints
> #the getHigh function
> def getHigh(pints, highPints):
> highPints = pints[0]
> counter = 1
> while counter < 7:
> if (pints[counter] > highPints):
> highPints = pints[counter]
The indentation here is wrong:
> counter = counter + 1
It will add 1 _only_ if pints[counter] > highPints.
> return highPints
> #the getLow function
> def getLow(pints, lowPints):
> lowPints = pints[0]
> counter = 1
> while counter < 7:
> if (pints[counter] < lowPints):
> lowPints = pints[counter]
The indentation here is wrong:
> counter = counter + 1
It will add 1 _only_ if pints[counter] < highPints.
> return lowPints
> #the displayInfo function
> def displayInfo(averagePints, highPints, lowPints):
> print "The average pints donated was: ", averagePints
> print "The highest amount of pints donated was: ", highPints
> print "The lowest amount of pints donated was: ", lowPints
Why is 'displayInfo' calling itself here?
> return displayInfo(averagePints, highPints, lowPints)
>
> main()
>
> The problem is that the display info isn't shown after the user types in their 7 numerical values. Please help.
>
More information about the Python-list
mailing list