Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.

Commit 2ff412e

Browse files
authored
Merge branch 'master' into master
2 parents f4f95d0 + d224884 commit 2ff412e

File tree

129 files changed

+14317
-38536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+14317
-38536
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ nosetests.xml
4848
coverage.xml
4949
*.cover
5050
.hypothesis/
51+
.pytest_cache/
5152

5253
# Translations
5354
*.mo
@@ -84,14 +85,17 @@ celerybeat-schedule
8485

8586
# dotenv
8687
.env
88+
*.csv
8789

8890
# virtualenv
8991
.venv
9092
venv/
9193
ENV/
9294
vclassroom/
95+
advclassroom/
9396
edu-collections/
9497

98+
9599
# Spyder project settings
96100
.spyderproject
97101
.spyproject
@@ -107,4 +111,3 @@ edu-collections/
107111

108112
# emacs
109113
*.*~
110-
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
# Programming in python B Winter 2018
3+
# March 11, 2018
4+
# Test cigar party test
5+
# Tracy Allen - git repo https://github.com/tenoverpar/Wi2018-Classroom
6+
7+
"""
8+
When squirrels get together for a party, they like to have cigars.
9+
A squirrel party is successful when the number of cigars is between
10+
40 and 60, inclusive. Unless it is the weekend, in which case there
11+
is no upper bound on the number of cigars.
12+
Return True if the party with the given values is successful,
13+
or False otherwise.
14+
"""
15+
16+
17+
def cigar_party(cigars, is_weekend):
18+
if is_weekend:
19+
return (cigars >= 40)
20+
else:
21+
return (cigars >= 40 and cigars <= 60)
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python
2+
from collections import OrderedDict
3+
4+
5+
# Programming in python B Winter 2018
6+
# March 11, 2018
7+
# Kwargs lab
8+
# Tracy Allen - git repo https://github.com/tenoverpar/Wi2018-Classroom
9+
10+
11+
"""
12+
call_colors() is a function that takes totaly generic arguments
13+
the test code calls it in various ways so you can confirm it works as expected.
14+
15+
colors_manual() takes generic arguments, but processes it as if it
16+
had keyworkd parameters.
17+
"""
18+
19+
20+
def colors(fore_color='red',
21+
back_color='blue',
22+
link_color='green',
23+
visited_color='cyan'):
24+
25+
output = ("The colors are: \n"
26+
" foreground: {fore_color}\n"
27+
" background: {back_color}\n"
28+
" link: {link_color}\n"
29+
" visited: {visited_color}")
30+
output = output.format(fore_color=fore_color,
31+
back_color=back_color,
32+
link_color=link_color,
33+
visited_color=visited_color)
34+
35+
return output
36+
37+
38+
def call_colors(*args, **kwargs):
39+
"""
40+
So this function will simpily return args and kwargs, and the test.
41+
42+
*args and **kwargs should be saved for times when you NEED generic
43+
function processing.
44+
"""
45+
return args, kwargs
46+
47+
48+
def colors_manual(*args, **kwargs):
49+
"""
50+
This example to show you how much work you need to do to do this by hand!
51+
52+
"""
53+
default_colors = OrderedDict((('fore_color', 'red'),
54+
('back_color', 'blue'),
55+
('link_color', 'green'),
56+
('visited_color', 'cyan')))
57+
58+
for key in kwargs:
59+
if key not in default_colors:
60+
msg = "colors_manual() got an expcted keyword argument: {}".format(key)
61+
raise TypeError
62+
63+
all_args = {}
64+
# uppacking now
65+
for i, key in enumerate(default_colors.keys()):
66+
try:
67+
all_args[key] = args[i]
68+
except IndexError:
69+
break
70+
71+
for key, color in default_colors.items():
72+
if key in all_args:
73+
if key in kwargs:
74+
msg = "colors_manual() go mult values for argument '{}'".format(key)
75+
raise TypeError(msg)
76+
elif key in kwargs:
77+
# from the dictionary
78+
all_args[key] = kwargs[key]
79+
else:
80+
all_args[key] = color
81+
82+
output = ("The colors are:\n"
83+
" foreground: {fore_color}\n"
84+
" back_color: {back_color}\n"
85+
" link: {link_color}\n"
86+
" visited: {visited_color}")
87+
output = output.format(**all_args)
88+
89+
return output

students/TracyA/session05/mailroom_session05.py students/TracyA/session06/mailroom_session06.py

+29-70
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# Tracy Allen - git repo https://github.com/tenoverpar/Wi2018-Classroom
99

1010

11-
donor_data = {"Allen, Paul": [1000000, 50000, 300000],
12-
"Gates, Bill": [5000000, 80000, 700000],
13-
"Warren, Buffett": [30000, 30000, 40000],
14-
"Musk, Elon": [1000000, 30000],
15-
"Zuckerberg, Mark": [10000, 50000, 12000, 400000]}
11+
donor_data = {"Allen, Paul": [1000000.00, 50000.00, 300000.00],
12+
"Gates, Bill": [5000000.00, 80000.00, 700000.00],
13+
"Warren, Buffett": [30000.00, 30000.00, 40000.00],
14+
"Musk, Elon": [1000000.00, 30000.00],
15+
"Zuckerberg, Mark": [10000.00, 50000.00, 12000.00, 400000.00]}
1616

1717

1818
# Donor data comprehension
@@ -60,16 +60,15 @@ def make_donor_dict(name, amount):
6060

6161
def donor_selection():
6262
name = input("Please enter a donor's name in the form "
63-
"of 'Last Name, First name' or 'list' to see a list of donors"
64-
" or menu to exit > ").title()
63+
"of 'Last Name, First name'. \n Enter 'list' to see a list of "
64+
"donors or 'menu' to exit > ").title()
6565
return name
6666

6767

6868
def get_donor_name():
6969
"""Attempt to break up and handle exceptions"""
7070
while True:
7171
name = donor_selection()
72-
print(">>>> name2", name)
7372
if name == "List":
7473
show_list()
7574
elif name == "Menu":
@@ -104,29 +103,6 @@ def get_donation_amount():
104103
return amount
105104

106105

107-
# def add_donor_info(name, donor_db):
108-
# """ Add donor info or add a new donor
109-
# :params: name/string/name of donor db key, donor_db: dictionary of
110-
# donor names/amts.
111-
# :return:
112-
# """
113-
# if name == "list" or name == "menu":
114-
# print('Please select a name other than list or menu.')
115-
# return 12
116-
# if name not in donor_db:
117-
# "create a name in the donor_db if it does not already exist"
118-
# donor_db.update({name.lower(): []})
119-
#
120-
# try:
121-
# amount = input("Enter amount of donor's contribution "
122-
# "(or 'list' to see all donors or 'menu' to exit)> ").strip()
123-
# donor_db[name].append(float(amount))
124-
# except ValueError:
125-
# print("\nPlease resubmit a the donor amount information in \
126-
# dollars and cents with a format matching: 10.11\n")
127-
# return
128-
129-
130106
def split_name(name):
131107
""" I can now split the names into first and last name"""
132108
first_name = name.split(",")[1].strip()
@@ -173,34 +149,6 @@ def send_donor_email():
173149
print(make_donor_email(donor_dict))
174150

175151

176-
# while True:
177-
# name = input("Please enter a donor's name in the form of \
178-
# 'Last name, First name' "
179-
# "(or 'list' to see a list of all donors, \
180-
# or 'menu' to exit)> ").strip()
181-
# if name == "list":
182-
# show_list()
183-
# elif name == "menu":
184-
# return None
185-
# else:
186-
# break
187-
# while True:
188-
# amount_str = input("Please enter a donation amount \
189-
# (or 'menu' to exit)> ").strip()
190-
# if amount_str == "menu":
191-
# return None
192-
# else:
193-
# amount = float(amount_str)
194-
# donor = get_donor(name)
195-
# if donor is None:
196-
# donor_data.setdefault(name, [])
197-
# donor_dict["first name"], donor_dict["last name"] = split_name(name)
198-
# donor_data[name].append(amount)
199-
# donor_dict["amt"] = amount
200-
# break
201-
# print(make_donor_email(donor_dict))
202-
203-
204152
def sort_key(item):
205153
""" key function used to sort the list by first (not zeroth) item"""
206154
return item[1]
@@ -212,18 +160,31 @@ def quit_program():
212160

213161

214162
def make_report():
215-
"""print the people to the screen"""
216-
rows = []
163+
"""Generate the report of the donors and amounts donated.
164+
:returns: the donor report as a string.
165+
"""
166+
# First, reduce the raw data into a summary list view
167+
report_rows = []
217168
for donor in donor_data:
218169
total = sum(donor_data[donor])
219170
num = len(donor_data[donor])
220171
avg = total / num
221-
rows.append((donor, total, num, avg))
222-
rows.sort(key=sort_key, reverse=True)
223-
print("{:20s}{:15s}{:15s}{:12s}".format(
224-
"Donor Name", "| Total Given", "| Num Gifts", "| Average Gift"))
225-
print("_" * 67)
226-
[print('{:20s}{:15.2f}{:^15d}{:12.2f}'.format(*row)) for row in rows]
172+
report_rows.append((donor, total, num, avg))
173+
174+
# sort the report data
175+
report_rows.sort(key=sort_key, reverse=True)
176+
report = []
177+
report.append("{:20s} | {:11s} | {:15s} | {:12s}".format(
178+
"Donor Name", "Total Given", "Num Gifts", "Average Gift"))
179+
180+
report.append("-" * 67)
181+
for row in report_rows:
182+
report.append("{:20s}${:15.2f}{:^15d}${:12.2f}".format(*row))
183+
return "\n".join(report)
184+
185+
186+
def print_donor_report():
187+
print(make_report())
227188

228189

229190
def init_prompt():
@@ -234,20 +195,18 @@ def init_prompt():
234195
'3' - Send letters to everyone
235196
'4' - Quit
236197
> ''')
237-
print(">>>>>> answer", answer)
238198
return answer
239199

240200

241201
if __name__ == "__main__":
242202
running = True
243203

244204
dispatch_dictionary = {"1": send_donor_email,
245-
"2": make_report,
205+
"2": print_donor_report,
246206
"3": create_letter_files,
247207
"4": quit_program}
248208
while running:
249209
response = init_prompt()
250-
print(">>>> response", response)
251210
try:
252211
dispatch_dictionary[response]()
253212
except KeyError:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
# Programming in python B Winter 2018
3+
# February 21 2017
4+
# Test cigar party script
5+
# Tracy Allen - git repo https://github.com/tenoverpar/Wi2018-Classroom
6+
7+
"""
8+
When squirrels get together for a party, they like to have cigars.
9+
A squirrel party is successful when the number of cigars is between
10+
40 and 60, inclusive. Unless it is the weekend, in which case there
11+
is no upper bound on the number of cigars.
12+
Return True if the party with the given values is successful,
13+
or False otherwise.
14+
"""
15+
16+
17+
# you can change this import to test different versions
18+
from cigar_party import cigar_party
19+
# from cigar_party import cigar_party2 as cigar_party
20+
# from cigar_party import cigar_party3 as cigar_party
21+
22+
23+
def test_1():
24+
assert cigar_party(41, False) is True
25+
26+
27+
def test_2():
28+
assert cigar_party(50, False) is True
29+
30+
31+
def test_3():
32+
assert cigar_party(70, True) is True
33+
34+
35+
def test_4():
36+
assert cigar_party(30, True) is False
37+
38+
39+
def test_5():
40+
assert cigar_party(50, True) is True
41+
42+
43+
def test_6():
44+
assert cigar_party(60, False) is True
45+
46+
47+
def test_7():
48+
assert cigar_party(61, False) is False
49+
50+
51+
def test_8():
52+
assert cigar_party(40, False) is True
53+
54+
55+
def test_9():
56+
assert cigar_party(39, False) is False
57+
58+
59+
def test_10():
60+
assert cigar_party(40, True) is True
61+
62+
63+
def test_11():
64+
assert cigar_party(39, True) is False

0 commit comments

Comments
 (0)