|
1 | | -# mailroom |
| 1 | +# mailroom script: Writes emails thanking donors for donation amounts and generates report of donations |
| 2 | +# |
| 3 | +import random |
| 4 | +import string |
| 5 | +import sys |
| 6 | +from collections import Counter |
2 | 7 |
|
3 | | -#my = dict(name='Chris', 'John', amount='1','2','3') |
4 | | -#my = dict(name='Chris', 'John', amount='1','2','3') |
5 | | -d = {'doner1': 'Chris C', 'doner2': 'John J','doner3': 'Matt M','doner4': 'Luke L','doner5': 'Eli E'} |
| 8 | +# Initial Dictionary of doners nd amounts |
| 9 | +d = {'Chris C': 200, 'John J': 300, 'Matt M': 400, 'Luke L': 100, 'Eli E': 500} |
6 | 10 | a = {'amount1': 1,'amount2': 2,'amount3': 3,'amount4': 4,'amount5': 5} |
7 | 11 |
|
8 | | -print("print the doners",d) |
9 | | -print("print the amounts",a) |
10 | | -# prompt for option |
| 12 | +#print("The doners are:",d) |
| 13 | +#print("print the amounts",a) |
11 | 14 |
|
12 | | - |
13 | | -#FIZZBUZZ function |
| 15 | +# function to get doner and the amount |
14 | 16 | def donfunc(option,name,amount): |
15 | 17 | #if thanks you: |
16 | 18 | if option == 'yes': |
17 | 19 | #print("print doner",name) |
18 | 20 | if name == "list": |
19 | | - print("print the list of doners",d) |
| 21 | + print("printing the list of doners.... ",d) |
20 | 22 | don_again = input('Enter full name of doner:') |
21 | 23 | dname = don_again |
22 | | - if don_again in (d): |
23 | | - print("print the list of doners",d) |
24 | | - else: |
25 | | - d['doner6'] = dname |
26 | | - #print("print the doners",d) |
27 | 24 | else: |
28 | 25 | dname = name |
29 | | - d['doner6'] = dname |
30 | | - # amount = input('Enter the donation amount:') |
31 | 26 |
|
32 | 27 | if amount.isdigit() == True: |
33 | | - print("print new amount",amount) |
| 28 | + #print("print new amount",amount) |
| 29 | + amount = int(amount) |
34 | 30 | else: |
35 | 31 | # print("enter a number please:") |
36 | 32 | amount = input('enter a number please:') |
37 | | - a['amount6'] = amount |
38 | | - print("print the list of doners",d) |
39 | | - print("print the list of amounts",a) |
| 33 | + amount = int(amount) |
| 34 | + #a['amount6'] = amount |
| 35 | + if dname in (d): |
| 36 | + d[dname] = d[dname] + amount |
| 37 | + else: |
| 38 | + d[dname] = amount |
| 39 | + #print("print the list of doners",d) |
| 40 | + #print("print the list of amounts",a) |
40 | 41 |
|
41 | 42 | #print("Dear %s,\n",%dname) |
42 | 43 | print('Dear {0},'.format(dname)) |
43 | | - print("Thank you for your {0}th donation".format(amount)) |
| 44 | + print("Thank you for your ${0}.00 donation".format(amount),'\n') |
44 | 45 | #don = input('Enter full name of doner or list:') |
45 | 46 |
|
46 | | -def repfunc(): |
| 47 | +def repeats(name,comp): |
| 48 | + if (name == comp): |
| 49 | + match = 1 |
| 50 | + return match |
| 51 | + |
| 52 | +def repfunc(count,dn): |
47 | 53 | #if opt2 == 'yes': |
| 54 | + #for i, item in enumerate(d): |
| 55 | + #print(a) |
| 56 | + l = len(d) |
| 57 | + #print(l) |
| 58 | + #ak = list(a)[i] |
| 59 | + #print(ak) |
| 60 | + tot = sum(d.values()) |
| 61 | + #print('total..........',tot) |
| 62 | + avg = tot/l |
| 63 | + numd = count |
| 64 | + n = ('{:s} ${:d}.00 {} ${:06.2f}.00'.format(dn,d[dn],numd,avg)) |
| 65 | + print(n) |
| 66 | + |
| 67 | +m = repeats(name="temp",comp="temp") |
| 68 | + |
| 69 | +#function to print out the report |
| 70 | +def report (): |
| 71 | + h = ('Doner Total Donation Count Average Donation') |
| 72 | + print(h) |
48 | 73 | for i, item in enumerate(d): |
49 | | - #print("the %ith item is: %s"%(i, item)) |
50 | | - print("the %ith doner is: %s"%(i,d.get(item))) |
| 74 | + f = list(d)[i] |
| 75 | + cnt = 0 |
| 76 | + for i in d.keys(): |
| 77 | + #print('iiiiiii',i) |
| 78 | + #print(cnt) |
| 79 | + m = repeats(name=f,comp=i) |
| 80 | + #print(m) |
| 81 | + if m == 1: |
| 82 | + cnt = cnt + 1 |
| 83 | + #print('count........',cnt) |
| 84 | + #print("the %ith item is: %s with count %i"%(i, d.get(item),cnt)) |
| 85 | + ndict = ('{:s}(count:{:d})'.format(f,cnt)) |
| 86 | + repfunc(count=ndict,dn=f) |
| 87 | + |
51 | 88 |
|
52 | 89 | opt1 = input('Send a Thank You?:') |
53 | 90 | opt2= input('Create a Report?:') |
54 | 91 |
|
55 | 92 |
|
56 | 93 | if opt1 == 'yes': |
57 | 94 | don = input('Enter full name of doner or list:') |
58 | | - amou = input('enter the donation number:') |
| 95 | + amou = input('enter the donation amount:') |
59 | 96 | #call the function |
60 | 97 | donfunc(option=opt1,name=don,amount=amou) |
61 | 98 | if opt2 == 'yes': |
62 | 99 | #call the function |
63 | | - repfunc() |
| 100 | + report() |
0 commit comments