def test_Charity_2(): c = Charity("Red Cross") c.AddDonor("Bill Gates", [10000, 5000.00, 42000.00]) c.AddDonor("Jeff Bezos", [1500.00]) c.AddDonor("Paul Allen", [50000, 4500.00]) DonorList = c.GetDonorList() assert DonorList == "------------------------------\n" + \ "Bill Gates\nJeff Bezos\nPaul Allen\n" + \ "------------------------------\n"
def test_Charity_3(): c = Charity("Red Cross") c.AddDonor("Bill Gates", [10000, 5000.00, 42000.00]) c.AddDonor("Jeff Bezos", [1500.00]) c.AddDonor("Paul Allen", [50000, 4500.00]) Report = "-----------------------------------------------------------\n" + \ "Red Cross\n" + \ "-----------------------------------------------------------\n" + \ "Donor Name | Total Given | Num Gifts | Average Gift\n" + \ "-----------------------------------------------------------\n" + \ "Bill Gates $ 57000.00 3 $ 19000.00\n" + \ "Paul Allen $ 54500.00 2 $ 27250.00\n" + \ "Jeff Bezos $ 1500.00 1 $ 1500.00\n" assert c.GetReport() == Report
def test_Charity_1(): c = Charity("Red Cross") c.AddDonor("Bill Gates", [10000, 5000.00, 42000.00]) c.AddDonor("Jeff Bezos", [1500.00]) c.AddDonor("Paul Allen", [50000]) assert c.CharityName == "Red Cross" assert "Bill Gates" in c.DonorList c.DonorList["Paul Allen"].AddDonation(4500.00) assert c.DonorList["Paul Allen"].Donations == [50000, 4500.00] DonorInfo = list() for donor in c.DonorList.items(): DonorInfo.append( f"{donor[1].DonorName}: {donor[1].TotalDonation():.2f}") assert ",".join(DonorInfo) == "Bill Gates: 57000.00," + \ "Jeff Bezos: 1500.00," + \ "Paul Allen: 54500.00"
def main(): input = "".join(open("mailroominput.txt", "r").readlines()) sys.stdin = io.StringIO(input) local_charity = Charity('Local Charity') local_charity.AddDonor('William Gates, III') local_charity.Donors['William Gates, III'].AddDonation(60000.00) local_charity.Donors['William Gates, III'].AddDonation(50000.00) local_charity.AddDonor('Mark Zuckerberg') local_charity.Donors['Mark Zuckerberg'].AddDonation(10000.00) local_charity.Donors['Mark Zuckerberg'].AddDonation(60000.00) local_charity.Donors['Mark Zuckerberg'].AddDonation(396.10) local_charity.AddDonor('Jeff Bezos') local_charity.Donors['Jeff Bezos'].AddDonation(877.33) user_input(local_charity)
def add_donation(): donor_input = "" confirm_input = "" donation_amount = "" donation_positive = False thank_you_prompt = "For main menu enter 'q' at any time.\n" + \ "Enter a donor's Full Name or enter 'list' to see " + \ "the donors list :" dontation_prompt = "Please enter donation amount: " while (donor_input != "q"): donor_input = input(thank_you_prompt) # Donors list and exiting options while donor_input == "list": print(Charity.GetDonorList()) donor_input = input(thank_you_prompt) if donor_input == "q": break while confirm_input.lower() not in ("y", "n", "q"): confirm_input = input( f"Is {donor_input} the donor's name? (y/n): ") if confirm_input.lower() == "q": break elif confirm_input.lower() == "n": donor_input = "" continue while (type(donation_amount) != float): donation_amount = input(dontation_prompt) if donation_amount == "q": break try: donation_amount = float(donation_amount) except ValueError: print('Please enter a number') if donation_amount < 0: donation_amount = "" print('Please enter a positive number') if donation_amount == "q": break # Assigning donor values if donor_input not in Charity.DonorList: Charity.AddDonor(donor_input, [donation_amount]) else: Charity.DonorList[donor_input].AddDonation(donation_amount) print(Charity.DonorList[donor_input].LatestDonation()) donor_input = "q"
def main(): # test Charity creation test_charity = Charity('local charity') assert (test_charity.CharityName == 'local charity') assert (test_charity.Donors == {}) # test AddDonor from Charity test_name = 'Kyle Clark' test_charity.AddDonor(test_name) assert (test_charity.Donors[test_name].Donations == []) # test functions of Donor amount = 1000.56 test_send_thank_you(test_charity, test_name, amount) # test send all thank yous of Charity test_send_all_thank_yous(test_charity)
folder = create_folder(folder_name) for name in Charity.DonorList: Charity.DonorList[name].TextFile(folder[0], folder[1]) def quit(): print("Thank you for using Mailroom.\nExiting Program\n") main_prompt = ("\nYou are in the main menu, Choose an action to perform:\n" + "1: Add a Donation.\n" + "2: Create a Report.\n" + "3: Send Thank You letter to a single donor.\n" "4: Send Thank You letters to all donors.\n" + "q: Quit\n") main_dispatch = { "1": add_donation, "2": create_report, "3": send_thank_you, "4": send_thank_you_all, "q": quit } if __name__ == '__main__': Charity = Charity("Red Cross") Charity.AddDonor("Paul Allen", [250.00, 433.49, 413.45]) Charity.AddDonor("Mark Zuckerberg", [3422.12, 5877.13, 4323.65]) Charity.AddDonor("Jeff Bezos", [877.33]) Charity.AddDonor("William Gates, III", [45523.16, 212333.12]) main_menu(main_dispatch)