Skip to content

Commit 34266d1

Browse files
committed
Week 3 homework
1 parent a857593 commit 34266d1

3 files changed

Lines changed: 150 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'''
2+
Created on Oct 1, 2014
3+
4+
@author: db345c
5+
'''
6+
7+
def rot13(s):
8+
alpha1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .!<>;:'"
9+
alpha2 = "NOPQRSTUVWXYZabcdefgjijklmnopqrstuvwxyzABCDEFGHIJKLM .!<>;:'"
10+
11+
# string to return
12+
ret = ""
13+
14+
for i in range(0, len(s)):
15+
try:
16+
if s[i].islower():
17+
ret += alpha2[alpha1.index(s[i])].lower()
18+
else:
19+
ret += alpha2[alpha1.index(s[i])].upper()
20+
except ValueError:
21+
pass
22+
else:
23+
pass
24+
return ret
25+
26+
# run the program with the assigned parameter
27+
if __name__ == '__main__':
28+
print rot13("Zntargvp sebz bhgfvqr arne pbeare")
29+
30+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
def list_lab():
3+
4+
# Part 1
5+
print "Part 1\n"
6+
lst = ["Apples", "Pears", "Oranges", "Peaches"]
7+
print lst
8+
fruit = raw_input("Enter another fruit: ")
9+
lst.append(fruit)
10+
print lst
11+
num = raw_input("Enter the nubmer: ")
12+
print num, lst[int(num) -1]
13+
print lst
14+
lst.insert(0, "Grape")
15+
print lst
16+
for i in lst:
17+
if i[0] == 'P':
18+
print i,
19+
20+
# Part 2
21+
print "\n\nPart 2\n"
22+
print lst
23+
lst.remove("Grape")
24+
print lst
25+
frt = raw_input("Enter the fruit to delete: ")
26+
print lst.remove(frt)
27+
print lst
28+
29+
# Part 3
30+
print "\nPart 3\n"
31+
for x in lst:
32+
prmpt = "Do you like " + x + "? : "
33+
a = raw_input(prmpt)
34+
if a == "yes":
35+
print x.lower()
36+
elif a == "no":
37+
lst.remove(x)
38+
39+
print lst
40+
41+
# Part 4
42+
print "\nPart 4\n"
43+
print "Original List", lst
44+
lst2 = lst[::]
45+
for idx, val in enumerate(lst2):
46+
lst2[idx] = val[::-1]
47+
48+
print "Modified list", lst2
49+
50+
51+
if __name__ == "__main__":
52+
list_lab()
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
def execute():
3+
donors = [["Jon Doe", 50, 2], ["Jane Doe", 35, 7], ["Anonymous", 30, 10]]
4+
prompt = "Please, select the following options\n1 - Send a Thank you Letter\n2 - Create Report\n3 - Quit\n"
5+
while True:
6+
print prompt
7+
answer = raw_input("What is your choice: ")
8+
if answer == '2':
9+
print_report(donors)
10+
elif answer == '1':
11+
generate_letters(donors)
12+
elif answer == '3':
13+
print "Have a good day"
14+
break
15+
else:
16+
print "Unrecognized option"
17+
print ""
18+
19+
def print_report(d):
20+
for donor in d:
21+
avg_amnt = 0
22+
if donor[2] == 0:
23+
avg_amnt = 0
24+
else:
25+
avg_amnt = donor[1]/donor[2]
26+
print "Name: %s\tTotal Donated: $%2.2f\tNumber of Donations: %i\tAverage Donation: $%2.2f" % (donor[0], donor[2], donor[1], avg_amnt)
27+
print ""
28+
29+
def generate_letters(d):
30+
name = select_donor(d)
31+
donation = get_donation(name)
32+
email_text = "Dear " + name + ",\n\nThank you very much for your generous donation of $" + str(donation) + ".\nThis donation will go a long way."
33+
email_text = email_text + "\n\nThank you again,\n\nSupport Staff"
34+
print "\n======================================================================="
35+
print email_text
36+
print "=======================================================================\n"
37+
for x in d:
38+
if x[0] == name:
39+
x[1] = x[1] + donation
40+
x[2] = x[2] + 1
41+
42+
def get_donation(n):
43+
while True:
44+
amount = raw_input("\nProvide donation amount: ")
45+
if float(amount):
46+
return float(amount)
47+
else:
48+
print "Invalid Number"
49+
print ""
50+
51+
def select_donor(d):
52+
while True:
53+
n = raw_input("\nType the name of the donor or type the work 'list': ")
54+
if n == "list":
55+
for x in d:
56+
print x[0]
57+
else:
58+
for x in d:
59+
# The comparison below does not work. I do not understand why....
60+
if x[0] == n:
61+
return n
62+
else:
63+
d.append([n, 0, 0])
64+
return n
65+
66+
if __name__ == "__main__":
67+
execute()
68+

0 commit comments

Comments
 (0)