This repository was archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmailroom.py
More file actions
81 lines (75 loc) · 2.81 KB
/
mailroom.py
File metadata and controls
81 lines (75 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def safe_input(str):
while 1:
try:
user_input=input(str)
break
except (EOFError, KeyboardInterrupt):
print("That's not a valid input")
return user_input
def sendThankYou():
response2=safe_input("Full Name?")
while response2=="list":
print(donorList.keys())
response2=input("Full Name?")
if not response2 in donorList:
donorList[response2]=[]
response3=safe_input("Donation Amount?")
while not response3.isdigit():
response3=input("I'm sorry, that is not a valid number. Please try again:")
donorList[response2].append(response3)
print("Oh glorious "+response2+". Thank you so much for your insane gift of $" +str(response3)+"! You are truly a magnificent human!")
def createReport():
totalDict={}
for person in donorList:
total,number,avg=0,0,0
for value in donorList[person]:
total+=int(value)
number+=1
avg=total/number
totalDict[person]=[total,number,avg]
sortedDict=sorted(totalDict.items(), key=operator.itemgetter(1))
gridprinter(sortedDict)
def gridprinter(dict):
size, squares,numEntries = 2,4,len(dict)
max=maxSize(dict)
#first element is actually number we need, not a value
max[0]=10**max[0]
for line in range((numEntries*2)+1):
printedLine = ""
if line%size==0:
for column in range(0,squares):
printedLine+=("+" + "-" * (len(str(max[column]))+2))
printedLine+=("+")
else:
for column in range(0, squares):
if column==0:
name=str(dict[int(line/size)][0])
else:
pass
name=str(dict[int(line/size)][1][column-1])
printedLine += ("|" + name + " " * (len(str(max[column])) + 2 - len(name)))
printedLine+=("|")
print(printedLine)
#Get max sizes to format grid
def maxSize(dict):
name,total,number,avg=0,0,0,0
for account in dict:
total = max(total,account[1][0])
number = max(number, account[1][1])
avg = max(avg, account[1][2])
name=max(len(account[0]),name)
return [name,total,number,avg]
import operator
import random
donorList = {"Randy": [], "Erin" : [], "Lexxy": [], "Bridgette" : [], "Liz": []}
for value in donorList:
for number in range(random.randrange(1,3)):
donorList[value].append(random.randrange(1,1000))
while 1:
response=safe_input("Would you like to \"Create a report\" or \"Send a thank you\"?")
if (response.lower()=="create a report" or response.lower()=="report"):
createReport()
elif (response.lower()=="send a thank you" or response.lower()=="thank you"):
sendThankYou()
else:
print("That's not a valid selection. Please try again")