121k views
5 votes
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. Use a loop in the program to run multiple times.

1 Answer

3 votes

Answer:

The program in Python is as follows:

num_pints = int(input("Pints: "))

sum_pints = 0

for i in range(num_pints):

blood = int(input("Blood Donated: "))

sum_pints += blood

print("Average: ",sum_pints/num_pints)

Step-by-step explanation:

This prompts the user for number of pints

num_pints = int(input("Pints: "))

This initializes the sum to 0

sum_pints = 0

This iterates through the number of pints

for i in range(num_pints):

This gets input for each blood donated

blood = int(input("Blood Donated: "))

This adds up all blood donated

sum_pints += blood

This calculates and prints the average

print("Average: ",sum_pints/num_pints)

User Dmitry Shvedov
by
3.4k points