@@ -47,7 +47,7 @@ def print_email(p_name, p_donation):
4747 print 'Dear %s, Thanks so much for your generous donation of $%s. It is greatly appreciated!' % (p_name , p_donation )
4848
4949def app_record (app_name , app_dbase ):
50- """ Append an existing record with new donations """
50+ """ Append an existing donor record """
5151 for i in range (len (app_dbase )):
5252 if app_name in app_dbase [i ]:
5353 app_donation = get_donation ()
@@ -57,7 +57,7 @@ def app_record(app_name, app_dbase):
5757 # print app_dbase
5858
5959def add_record (add_name , add_dbase ):
60- """ Call get_donation and add new donor to database with result """
60+ """ Add new donor to database """
6161 add_donation = get_donation ()
6262 new = [add_name , add_donation ]
6363 add_dbase .append (new )
@@ -85,20 +85,32 @@ def thank_you(dbase):
8585 add_record (name , dbase )
8686 # print 'in thank_you, returning from add_record--', dbase
8787
88- def mk_report ():
88+ def mk_report (rep_dbase ):
8989 """ Create a sorted list of donors"""
90- print 'Report'
90+
91+ print 'Donor Name\t \t \t Total Donation\t # of Donations\t \t Average Donation'
92+ for j in range (len (rep_dbase )):
93+ donor_sum = 0
94+ donor_slice = rep_dbase [j ][1 :]
95+ num_donations = (len (donor_slice ))
96+ for k in range (len (donor_slice )):
97+ donor_sum += int (donor_slice [k ])
98+ avg_donation = donor_sum / num_donations
99+ print '%s\t \t \t %s\t \t \t \t %s\t \t \t \t \t \t %s' % (rep_dbase [j ][0 ], donor_sum , num_donations , avg_donation )
100+
91101
92102if __name__ == '__main__' :
93103 donor = mk_dbase ()
94104 answer = None
95105 while not (answer == "q" ):
96106 answer = get_input ()
97- if answer == "1" :
107+ if answer == "q" :
108+ break
109+ elif answer == "1" :
98110 thank_you (donor )
99111 # print '--in main--, after thank_you returns', donor
100112 else :
101- mk_report ()
113+ mk_report (donor )
102114 print "Exiting"
103115
104116
0 commit comments