Skip to content

Commit 26c3c44

Browse files
committed
Merge pull request UWPCE-PythonCert#45 from jerrytozhang/master
adding mailroom.py Merging this now -- could use some clean up, but you clearly get the concepts I wanted you to get. Nice work.
2 parents b68f976 + d833b04 commit 26c3c44

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from mailroomfunction import sendletter
2+
from mailroomfunction import printout
3+
4+
Userlist = ['Jerry', [10, 20, 30], 'Peter', [5, 6], 'Aly', [3, 4], 'Anisha', [11, 15, 13], 'Chris', [9, 11, 14], 'Vini', [13, 17, 16]]
5+
6+
input1 = input("To send a Thanks You letter, press '1'\nTo create a report, press '2'\nTo Exit, press '0' \n")
7+
8+
while input1:
9+
if input1 == 1:
10+
sendletter(Userlist, input1)
11+
input1 = input("To send a Thanks You letter, press '1'\nTo create a report, press '2'\nTo Exit, press '0' \n")
12+
elif input1 == 2:
13+
printout(Userlist, input1)
14+
input1 = input("To send a Thanks You letter, press '1'\nTo Create a report, press '2'\nTo Exit, press '0' \n")
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
3+
def sendletter(Userlist, input1):
4+
# Print out all existing donators name.
5+
print Userlist[::2]
6+
username1 = raw_input("Please type a name from above existing Donator List or enter a new name: ")
7+
# Verify if input are all digis.
8+
amount1 = raw_input("Please input the amount of your donation: ")
9+
# Determine if your input is digi.
10+
while not amount1.isdigit():
11+
print "Error, your input is not a number!!!"
12+
amount1 = raw_input("Please input the amount of your donation: ")
13+
# Determine if the donator name just typed in is actually in the list.
14+
# If it is in the list, then do the below:
15+
if username1 in Userlist:
16+
locationuser1 = Userlist.index(username1)
17+
Userlist[locationuser1 + 1].append(int(amount1))
18+
# If it is not in the list, then append it in the list.
19+
else:
20+
Userlist.append(username1)
21+
Userlist.append([int(amount1)])
22+
print '\n'
23+
print "Thank you, " + username1 + ", for your generous donation of amount of: $" + amount1 + " Dollars ! \n\n"
24+
return
25+
26+
if __name__ == "__main__":
27+
# execute only if run as a script
28+
main()
29+
30+
def printout(Userlist, input1):
31+
#initilize a list named donator_tuples
32+
donator_tuples = []
33+
# create a list wiht donator name, sum of donation, times of donation and average donation.
34+
for username2 in Userlist[::2]:
35+
locationuser2 = Userlist.index(username2)
36+
amount2 = sum(Userlist[locationuser2 + 1])
37+
# calculate how many times of donation
38+
length2 = len(Userlist[locationuser2 + 1])
39+
# calculate average donation
40+
average2 = int(amount2 / length2)
41+
donator_tuples.append([username2, amount2, length2, average2])
42+
# sort the list: donator_tuples by sum of donation.
43+
donator_tuples_sorted = sorted(donator_tuples, key=lambda donator: donator[1])
44+
print '\n\n'
45+
# Left align strings to be printed out
46+
print '{0:<10} {1:<8} {2:<8} {3:<8}'.format("Donator", "Total", "Times", "Average")
47+
for username3 in donator_tuples_sorted:
48+
# Left align strings/numbers in the sorted list: donator_tuples_sorted to be printed out
49+
print '{0:<10s} ${1:<7d} {2:<8d} ${3:<8d}'.format(username3[0], username3[1], username3[2], username3[3])
50+
print '\n'
51+
return
52+
53+
if __name__ == "__main__":
54+
# execute only if run as a script
55+
main()

0 commit comments

Comments
 (0)