11
22def execute ():
3+ """Run the main program """
34 donors = [["Jon Doe" , 50 , 2 ], ["Jane Doe" , 35 , 7 ], ["Anonymous" , 30 , 10 ]]
45 prompt = "Please, select the following options\n 1 - Send a Thank you Letter\n 2 - Create Report\n 3 - Quit\n "
56 while True :
@@ -17,52 +18,56 @@ def execute():
1718 print ""
1819
1920def print_report (d ):
21+ """Print users' report"""
2022 for donor in d :
2123 avg_amnt = 0
2224 if donor [2 ] == 0 :
2325 avg_amnt = 0
2426 else :
2527 avg_amnt = donor [1 ]/ donor [2 ]
26- print "Name: %s\t Total Donated: $%2.2f\t Number of Donations: %i\t Average Donation: $%2.2f" % (donor [0 ], donor [2 ], donor [1 ], avg_amnt )
28+ print "Name: %s\t Total Donated: $%2.2f\t Number of Donations: %i\t Average Donation: $%2.2f" % (donor [0 ], donor [1 ], donor [2 ], avg_amnt )
2729 print ""
2830
2931def generate_letters (d ):
32+ """Generate Thank you letter"""
3033 name = select_donor (d )
3134 donation = get_donation (name )
3235 email_text = "Dear " + name + ",\n \n Thank you very much for your generous donation of $" + str (donation ) + ".\n This donation will go a long way."
3336 email_text = email_text + "\n \n Thank you again,\n \n Support Staff"
3437 print "\n ======================================================================="
3538 print email_text
3639 print "=======================================================================\n "
37- for x in d :
38- if x [0 ] == name :
39- x [1 ] = x [1 ] + donation
40- x [2 ] = x [2 ] + 1
40+ for k in d :
41+ if k [0 ] == name :
42+ k [1 ] = k [1 ] + float ( donation )
43+ k [2 ] = k [2 ] + 1
4144
4245def get_donation (n ):
46+ """Obtain donation ammount"""
4347 while True :
4448 amount = raw_input ("\n Provide donation amount: " )
45- if float ( amount ) :
46- return float (amount )
47- else :
48- print "Invalid Number"
49- print ""
49+ try :
50+ if float (amount ):
51+ return float ( amount )
52+ except ValueError :
53+ print "Invalid Number provided for donation "
5054
5155def select_donor (d ):
56+ """Obtain Donor name to use"""
5257 while True :
5358 n = raw_input ("\n Type the name of the donor or type the work 'list': " )
5459 if n == "list" :
60+ print n == "list"
5561 for x in d :
5662 print x [0 ]
5763 else :
58- for x in d :
59- # The comparison below does not work. I do not understand why....
60- if x [0 ] == n :
61- return n
62- else :
63- d .append ([n , 0 , 0 ])
64+ for g in d :
65+ if g [0 ] == n :
6466 return n
67+ d .append ([n , 0 , 0 ])
68+ return n
6569
6670if __name__ == "__main__" :
71+ """Execute the main program"""
6772 execute ()
6873
0 commit comments