Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR request 12-15-2018 #220

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions notes_for_class/source/index.rst

This file was deleted.

Empty file.
69 changes: 52 additions & 17 deletions students/ChengLiu/session03/mailroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,68 @@
Mailroom Part 1
"""

import os


OUT_PATH = "thank_you_letters"


def prepare_to_run():
if not os.path.isdir():
os.mkdir(OUT_PATH)


donors = [("Fred Jones", [100, 200, 300]), ("Amy Shume", [2000, 1000, 3000])]


def find_donor(name):
"""
finds if a donor is in the donor db
:param name: name of donor to find
: returns: the donor tuple if found, or None if not
"""
for donor in donors:
if name.lower() == donor[0].lower():
return donor
return None


def thank_you():
print("Do the Tahnk_you function here")

filename = os.path.join("folders", filename)



def report():
print("Do the report function here")


def menu_selection(prompt, dispatch_dict):



def main():
print("Welcome to Mailroom!")
answer = ""
while answer != "q":
print("Please select from the following:")
print("Quit: 'q'"
"\nThank you: 't'"
"\nReport: 'r'"
)
answer = input("=> ")
answer = answer.strip() # in case entering the space at the beginning
answer = answer[0:1].lower() # in case only enter key, no values
if answer == "t":
thank_you()
elif answer == "r":
report()
answer = ""
while answer != "q":
print("Please select from the following:")
print("Quit: 'q'"
"\nThank you: 't'"
"\nReport: 'r'"
)
answer = input("=> ")
answer = answer.strip() # in case entering the space at the beginning
answer = answer[0:1].lower() # in case only enter key, no values
if answer == "t":
thank_you()
elif answer == "r":
report()


if __name__ == "__main__":
main()


# main()
prepare_to_run()
assert find_donor("Fred Jones") is not None
assert find_donor("Bob Jones") is not None
assert find_donor("Fred jones") is not None
2 changes: 1 addition & 1 deletion students/ChengLiu/session03/slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Slicing
"""

items = ['a','b','c','d','e']
items = ['a', 'b', 'c', 'd', 'e']
items = items * 4
print(items)

Expand Down
2 changes: 1 addition & 1 deletion students/ChengLiu/session03/strformat_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


values = input("Enter three numbers: ")
print("the 3 numbers are: {:d}, {:d}, {:d}".format(values(0),values(1), values(2)))
print("the 3 numbers are: {:d}, {:d}, {:d}".format(values(0), values(1), values(2)))


element = ['oranges', 1.3, 'lemons', 1.1]
Expand Down
17 changes: 17 additions & 0 deletions students/ChengLiu/session04/letters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-------------------------------------------------------
Hello Mr cool! Thank you for your donation of $1000.00.
--------------------------------------------------------------------------------------------------------------
Hello Fred jones! Thank you for your donation of $300.00.
--------------------------------------------------------------------------------------------------------------
Hello Amy shume! Thank you for your donation of $3000.00.
--------------------------------------------------------------------------------------------------------------
Hello David cool! Thank you for your donation of $1000.00.
--------------------------------------------------------------------------------------------------------------
Hello Mr cool! Thank you for your donation of $1000.00.
--------------------------------------------------------------------------------------------------------------
Hello Fred jones! Thank you for your donation of $300.00.
--------------------------------------------------------------------------------------------------------------
Hello Amy shume! Thank you for your donation of $3000.00.
--------------------------------------------------------------------------------------------------------------
Hello David cool! Thank you for your donation of $1000.00.
-------------------------------------------------------
100 changes: 100 additions & 0 deletions students/ChengLiu/session04/mailroom-part2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env python3

"""
PY210A-Session 04
Cheng Liu
Mail-room Part 2
"""


import sys

donors = {'fred jones': ("Fred Jones", [100, 200, 300]),
'amy shume': ("Amy Shume", [2000, 1000, 3000]),
'david cool': ("David Cool", [1000]),
}


def show_donors():
current_donor = []
for donor in donors.values():
current_donor.append(donor[0])
return "\n".join(current_donor)


def find_donors(name):
key = name.strip().lower()
return donors.get(key)


def menu():
print("\n\n\n" + "Choose an action:")
print("1 - Send a Thank You to a single donor."
"\n2 - Create a Report."
"\n3 - Send letters to all donors."
"\n4 - Quit.")
selection = input("=> ")
selection = selection.strip().lower()
selection = selection[0:1] # in case only enter key, no values
return selection


def email_note(name):
key = name.strip().lower()
return ("-" * 55 + "\nHello {}! Thank you for your donation of ${:.2f}.".format(donors.get(key)[0].capitalize(), donors.get(key)[1][-1]) + "\n" + "-" * 55)


def thank_you():
name = ""
while True:
name = input("Enter 'list' to show the donors "
"or enter a Name to send a Thank You note, "
"or 'q' to quit.")
name = name.strip().lower()
donor = find_donors(name)
if name == "list":
print(show_donors())
elif name == 'q':
break
elif donor is None:
donation = float(input("Enter the amount: "))
donors[name] = (name.capitalize(), [donation])
print(email_note(name))
else:
print(email_note(name))


def report():
report_rows = []
for (donor, donation) in donors.values():
total_given = sum(donation)
num_gifts = len(donation)
avg_gift = total_given / num_gifts
report_rows.append((donor, total_given, num_gifts, avg_gift))

print("{:<25s} | {:>11s} | {:>9s} | {:>12s}".format("Donor Name", "Total Given", "Num Gifts", "Average Gift"))
print("-" * 70)

for row in report_rows:
print("{:<25s} {:>11.2f} {:>9d} ${:>12.2f}".format(row[0], row[1], row[2], row[3]))


def save_to_disk():
for donor in donors.values():
letter = email_note(donor[0])
open('letters.txt', 'a').write(letter)


def quit():
sys.exit(0)


if __name__ == "__main__":
running = True
selection_dict = {"1": thank_you,
"2": report,
"3": save_to_disk,
"4": quit}
while running:
selection = menu().strip()
selection_dict.get(selection)()
Loading