1+ from textwrap import dedent
2+ import math
3+
4+ # Original list of historical donors and their amounts donated
5+ donations = []
6+ donations .append ( ("Marshawn Lynch" , [238.99 , 159.23 ]) )
7+ donations .append ( ("Russell Wilson" , [9910.00 , 159.23 , 357.00 ]) )
8+ donations .append ( ("Richard Sherman" , [426.48 , 3859.94 , 5496.00 ]) )
9+ donations .append ( ("Kam Chancellor" , [999.99 ]) )
10+ donations .append ( ("Bobby Wagner" , [999.99 ]) )
11+
12+ def show_donations ():
13+ x = 0
14+ print "\n The names of previous donors are: "
15+ for person in donations :
16+ print donations [x ][0 ]
17+ x += 1
18+
19+ def write_thank_you (name , amount ):
20+ print dedent ('''
21+ Dear %s,
22+ Thank you for your very kind donation of $%d.
23+ It will be put to very good use.
24+ Sincerely,
25+ -The Team
26+ ''' ) % (name , amount )
27+
28+ def check_add_donators (name ):
29+ x = 0
30+ move_on = False
31+ for person in donations :
32+ if name .lower () == donations [x ][0 ].lower ():
33+ print "\n %s is a previous donor!" % donations [x ][0 ]
34+ choice = None
35+ while not choice :
36+ amount = raw_input ("Please add another donation entry for this individual. Be sure to enter an integer or float: " )
37+ try :
38+ choice = float (amount )
39+ except ValueError :
40+ print "Must be an integer or float value!"
41+ donations [x ][1 ].append (float (amount ))
42+ write_thank_you (donations [x ][0 ], float (amount ))
43+ move_on = True
44+ x += 1
45+ if move_on == False :
46+ print "\n %s is a new donor! Adding the name to registry." % name
47+ choice = None
48+ while not choice :
49+ amount = raw_input ("How much $ did this individual donate? Be sure to enter an integer or float: " )
50+ try :
51+ choice = float (amount )
52+ except ValueError :
53+ print "Must be an integer or float value!"
54+ donations .append ( (name , [float (amount )]) )
55+ write_thank_you (name , float (amount ))
56+
57+ def sort_key (item ):
58+ return item [1 ]
59+
60+ def create_report ():
61+ report = []
62+ for (name , amount ) in donations :
63+ total = sum (amount )
64+ count = len (amount )
65+ avg = total / count
66+ report .append ( (name , total , count , avg ) )
67+ report .sort (key = sort_key )
68+ print "%25s | %11s | %9s | %12s" % ("Name" , "Total Donated" , "Freq Donated" , "Avg Donated" )
69+ print "-" * 66
70+ x = 0
71+ for row in report :
72+ print "%25s %11.2f %12i %17.2f" % row
73+
74+ print "\n "
75+ print "*" * 10 , "Welcome to the Mailroom command-line script" , "*" * 10
76+ while True :
77+ print dedent ('''
78+ Type "list" to show the names of our donors. Type "Thank You" to generate
79+ a thank-you letter to a donor. Type "Create Report" to generate a report
80+ of our donors which includes their number of donations, average donation,
81+ and total donation amounts. Finally, type "Exit" to exit the program.''' )
82+ response = raw_input ("\n Which option you like to select?: " )
83+ if response .lower () == "list" :
84+ show_donations ()
85+ if response .lower () == "thank you" :
86+ name_query = raw_input ("Enter the full name of the donor: " )
87+ check_add_donators (name_query )
88+ if response .lower () == "create report" :
89+ create_report ()
90+ if response .lower () == "exit" :
91+ print "Exiting now..."
92+ break
93+
0 commit comments