mardi 9 août 2016

Python - two arrays (one for donation amount, one for charity number), how to create a third array counting total donations for each charity?

For my assignment I have to do the following:

  • List of 100 random donations to 15 different charities.

  • Two arrays (one float one integer) of charities and donations ($1.00-$100.00)

  • Then, create a third array of the total donations for each charity.
  • Create a fourth array of the number of donations for each charity.
  • Print out the total for each charity and the average donation for each charity.
  • For each donation, print if it was below, equal to, or above the average donation for that charity and how much it differs from the average.

Can someone help me figure out how to create the third array? How do I link the charity number in array one to the corresponding donations in array two? This is all I have so far:

import random
from array import *

print("Charity","Donations",sep="\t")

counter = 0
donlist = []
charlist = []

while counter != 101:
    d = random.uniform(1.00,100.00)
    c = random.randint(1,15)
    counter +=1
    donlist.append(d)
    charlist.append(c)
    print(d,c)




Aucun commentaire:

Enregistrer un commentaire