Skip to content

Commit a1ed914

Browse files
author
Anastomose
committed
Added init block, listing function
1 parent a505f80 commit a1ed914

1 file changed

Lines changed: 33 additions & 13 deletions

File tree

‎Students/ebuer/session_03/mailroom.py‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def client_check(nme, donors):
4848
return False
4949

5050

51-
#function takes no arguments, prompts for value then validates and returns float
51+
#function takes no arguments, prompts for value then
52+
#validates and returns float
53+
5254
def donation_func():
5355
val_donation = False
5456
while not val_donation:
@@ -60,9 +62,15 @@ def donation_func():
6062
print "Sorry, that wasn't a valid donation.\n"
6163
return usr_donation
6264

63-
# #function that takes a tuple and creates a formatted string
64-
# def tuple_printer(tup):
65-
# for n in tup:
65+
## test block prior to starting mailroom
66+
if __name__ is '__main__':
67+
assert person_len(('Archer', 'Sterling')) == 14
68+
69+
l, f = name_split('Sterling Archer')
70+
assert l == 'Archer'
71+
assert f == 'Sterling'
72+
73+
print 'Initial tests pass.\n'
6674

6775

6876
#mailroom looping we will used bored for flow control since that
@@ -82,19 +90,27 @@ def donation_func():
8290

8391
## sending a thank you
8492
if not report_opt:
85-
usr_name = raw_input('Please enter a name or m for menu: ')
93+
usr_name = raw_input('Please enter a name, m for menu, or "list" for a list of donors: ')
8694

8795
if usr_name == 'm':
8896
continue
8997

98+
if usr_name == 'list':
99+
print '\n'
100+
for person in donors:
101+
print '{first} {last}'.format(last = person[0], first = person[1])
102+
print '\n'
103+
continue
104+
90105
#existing name, scan records and insert new donation
91106
if client_check(usr_name, donors):
92107
usr_donation = donation_func()
93108

94109
for person in client_list:
95110
#need to get correct record
96111
if name_split(usr_name) in person:
97-
new_record = (name_split(usr_name), (person[1] + (usr_donation,)))
112+
new_record = (name_split(usr_name),
113+
(person[1] + (usr_donation,)))
98114
client_list[client_list.index(person)] = new_record
99115

100116
#new donor, just append the name and donation to the end of the list
@@ -115,30 +131,31 @@ def donation_func():
115131

116132
elif report_opt == 1:
117133
#print a report of all donors and donations
118-
#find max person name length
134+
135+
client_list.sort()
136+
donors, donations = list_maker(client_list)
137+
138+
#find max name length
119139
name_length_value = 0
120140
for d in donors:
121141
if person_len(d) > name_length_value:
122142
name_length_value = person_len(d)
123143

124144
name_length_value += 5 # need to add some space after the name
125145

126-
127-
print '{0: >{l}}'.format(' ',l=name_length_value),
146+
print '{0: >{l}}'.format(' ', l=name_length_value),
128147
print '{a: >8} {b: >8} {c: >8} {d: >8}'\
129-
.format(a='Num', b='Total', c='Avg', d='Donations')
148+
.format(a='Num', b='Total', c='Avg', d='Donations')
130149

131150
for person in donors:
132151
i = donors.index(person)
133-
#print '{f} {l}'.format(f=person[1], l=person[0]),
134152

135153
l = len(donations[i])
136154
avg_d = 0
137155
tot_d = 0
138156
d_list = [] # d-listed, hilarious
139157
c_list = []
140158

141-
142159
for d in donations[i]:
143160
avg_d += d / l
144161
tot_d += d
@@ -163,4 +180,7 @@ def donation_func():
163180
bored = False
164181

165182
else:
166-
print "\nSorry, that isn't an option, please choose from 0 to 2.\n"
183+
print \
184+
"\nSorry, that isn't an option, please choose from 0 to 2.\n"
185+
186+

0 commit comments

Comments
 (0)