@@ -30,7 +30,7 @@ def get_donor_db():
3030
3131def list_donors ():
3232 """
33- creates a list of the donors as a string, so they can be printed
33+ Create a list of the donors as a string, so they can be printed
3434
3535 Not calling print from here makes it more flexible and easier to
3636 test
@@ -43,10 +43,9 @@ def list_donors():
4343
4444def find_donor (name ):
4545 """
46- find a donor in the donor db
46+ Find a donor in the donor db
4747
4848 :param: the name of the donor
49-
5049 :returns: The donor data structure -- None if not in the donor_db
5150 """
5251 key = name .strip ().lower ()
@@ -58,7 +57,6 @@ def add_donor(name):
5857 Add a new donor to the donor db
5958
6059 :param: the name of the donor
61-
6260 :returns: the new Donor data structure
6361 """
6462 name = name .strip ()
@@ -88,7 +86,6 @@ def gen_letter(donor):
8886 Generate a thank you letter for the donor
8987
9088 :param: donor tuple
91-
9289 :returns: string with letter
9390
9491 note: This doesn't actually write to a file -- that's a separate
@@ -104,22 +101,10 @@ def gen_letter(donor):
104101 ''' .format (donor [0 ], donor [1 ][- 1 ]))
105102
106103
107- def send_thank_you ( ):
104+ def take_donation ( name ):
108105 """
109- Execute the logic to record a donation and generate a thank you message.
106+ Ask user for donation amount, and then add it to the DB
110107 """
111- # Read a valid donor to send a thank you from, handling special commands to
112- # let the user navigate as defined.
113- while True :
114- name = input ("Enter a donor's name (or list to see all donors or "
115- "'menu' to exit)> " ).strip ()
116- if name == "list" :
117- print (list_donors ())
118- elif name == "menu" :
119- return
120- else :
121- break
122-
123108 # Now prompt the user for a donation amount to apply. Since this is
124109 # also an exit point to the main menu, we want to make sure this is
125110 # done before mutating the db.
@@ -149,9 +134,27 @@ def send_thank_you():
149134
150135 # Record the donation
151136 donor [1 ].append (amount )
137+ # print the thank you letter
152138 print (gen_letter (donor ))
153139
154140
141+ def send_thank_you ():
142+ """
143+ Execute the logic to record a donation and generate a thank you message.
144+ """
145+ # Read a valid donor to send a thank you from, handling special commands to
146+ # let the user navigate as defined.
147+ while True :
148+ name = input ("Enter a donor's name or 'list' to see all donors or "
149+ "'menu' to exit to main menu > " ).strip ()
150+ if name == "list" :
151+ print (list_donors ())
152+ elif name == "menu" :
153+ return
154+ else :
155+ take_donation (name )
156+
157+
155158def sort_key (item ):
156159 # used to sort on name in donor_db
157160 return item [1 ]
@@ -192,6 +195,7 @@ def save_letters_to_disk():
192195 letter = gen_letter (donor )
193196 # I don't like spaces in filenames...
194197 filename = donor [0 ].replace (" " , "_" ) + ".txt"
198+ print ("writting letter to:" , donor [0 ])
195199 open (filename , 'w' ).write (letter )
196200
197201
@@ -200,15 +204,19 @@ def print_donor_report():
200204
201205
202206def quit ():
207+ """
208+ quit the program
209+
210+ Note: you could put the sys.exit call directly in the dict
211+ but this lets you put extra code in there if you want.
212+ """
203213 sys .exit (0 )
204214
205215
206216if __name__ == "__main__" :
207217
208218 donor_db = get_donor_db ()
209219
210- running = True
211-
212220 selection_dict = {"1" : send_thank_you ,
213221 "2" : print_donor_report ,
214222 "3" : save_letters_to_disk ,
0 commit comments