HELP !! can someone take a look at this and see what i am doing wrong.

0 donald goggleye · May 28, 2015
The American Red Cross wants you to write a program that will 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 displayed.  Additionally, the highest and the lowest number of pints donated should be determined and displayed.  Write a loop around the program to run multiple times. 
 
Step:1 declare the following variables:
 
An array named pints of the data type Real of size 7
A variable named totalPints of the data type Real
A variable named averagePints of the data type Real initialized to 0
A variable named highPints of the data type Real initialized to 0
A variable named lowPints of the data type Real initialized to 0

above is the begining data
______________________________________________________


below is the python code i came up with i get errors and am not understanding what is happening
i am very new to this





# Donald Goggleye
# This lab will convert the blood drive program from LAB 9.1

#Lab 9-4 Blood Drive

#the main function

def main():


while endProgram == 'no':
print
# declare variables
Declare Real SIZE = 7
Declare Real pints[SIZE]
Declare Real totalPints = 0
Declare Real AveragePints = 0
Declare Real highPints[0]
Declare Real lowPints[0]
Declare counter = 0
Pints = [0] *7



 
# function calls
# the getPints function
pints = getPints(pints)
counter = 0
while counter < 7:
    pints[counter]=input ("Enter pints collected:")
    counter = counter +1

return pints

#the getTotal function

totalPints = getPints(pints, totalPints)
counter = 0
while counter < 7:
    totalPints = (totalPints + pints[counter])
    counter = counter +1

return totalPints

#the getAverage function

averagePints = getAverage(totalPints, [SIZE])
averagePints = (averagePints / 7)

return averagePints

#the getHigh function

hightPints = getHigh(pints, highPints)
hightPints[0]
counter = 1
while counter < 7:
    highPints = (highPints, pints[counter])
        if pints[counter] >highPints
            then highPints = pints[counter]
        end if
return highPints

#the getLow function


lowPints = getLow(pints, lowPints)
lowPints[0]
counter = 1
while counter < 7:
    lowPints = (lowPints, pints[counter])
        if pints[counter] < lowPints
            then lowPints = pints[counter]
        end if
return lowPints

#the displayInfo function
print( " the average pints donated is", averagePints )
print (" the highest number of pints donated", highPints)
print ( " the lowest number of pints donated", 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): ')





# calls main
main()



Post a Reply

Replies

Oldest  Newest  Rating
0 Halcyon Abraham Ramirez · May 30, 2015
Step:1 declare the following variables:

An array named pints of the data type Real of size 7
A variable named totalPints of the data type Real
A variable named averagePints of the data type Real initialized to 0
A variable named highPints of the data type Real initialized to 0
A variable named lowPints of the data type Real initialized to 0
0 Halcyon Abraham Ramirez · May 30, 2015
class RedCross:
    def __init__(self):
        self.totalPints = 0
        self.people = 0
        self.averagePints = []
        self.low_to_high = []
        self.pints_given = 0

    def addPints(self):
        Done = input("Do you want to add pints of blood? ")
        while Done != "N":
            
    
            pints_given = input("How Many Pints? ")    
            self.totalPints += pints_given
            self.low_to_high.append(pints_given)
            self.people += 1
            Done = input("Do you want to add even more pints of blood? ")

    def Total(self):
        print("\nThe number of pints today is {}".format(self.totalPints))
        


    def Average(self):
        average = self.totalPints / self.people
        print("\nthe average pint today is {}\n".format(average))

    def highest_to_lowest(self):
        self.low_to_high.sort()
        print("the lowest to highest orders of blood donated is",", ".join( str(i) + " pints" for i in self.low_to_high))
        
        
        
        
    def main(self):
        self.addPints()
        self.Total()
        self.Average()
        self.highest_to_lowest()

a = RedCross()
a.main()




this is my solution to your problem just thought I'd take a shot at it
        
    
+1 Dol Lod · May 28, 2015
When you say error, are you referring to a logic error or syntax error?

In Python, indentation is everything. However, posting on this site loses all indentation. If you want help, you would have to paste at ideone.com and then have people examine the code. Alternatively, while highly unlikely, try using code tags and see if it works.
  • 1

Python

107,241 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator