Ten potential donors have been asked to contribute today. Create the Python code that calculates the total number of dollars donated. Use a for loop to process the donations. Use a while loop to check that the amount contributed is not a negative number. Once the records have been processed, the program prints the total number of dollars donated.

Respuesta :

Answer:

The code with comments is given below:

# Create a function called process_donations

def process_donations():

   # Initialize the variables total and amount

   total = 0

   amount = 0

   # Create a for loop from 1 to 10 to process each donator

   for i in range(1,11):

       # Print out the donator number

       print("Donator#{}".format(i))

       # Get the amount from user

       amount = int(input("Please enter the amount you're going to donate:"))

       # Use a while loop to check if the amount is greater than 0

       # if not request a valid amount

       while amount <= 0:

           amount = int(input("Enter a valid amount: "))

       # Add the amount to total variable

       total += amount

   # Print the total donated

   print("The total donated is: ${}".format(total))

       

# Create the main function

def main():

   # Call the process_donations

   process_donations()

# When the program is going to run it calls the main function

if __name__ == "__main__":

   main()

Explanation:

Here I've attached a screenshot with the program functionality to show a better approach of the program running.

Ver imagen jf23perez