Skip to content

Commit b68f976

Browse files
committed
Merge pull request UWPCE-PythonCert#44 from PrimusPilus/master
Adding session 03 homework, still working on mailroom:wq!
2 parents 58f6f68 + a289989 commit b68f976

3 files changed

Lines changed: 239 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#Create a list that contains “Apples”, “Pears”, “Oranges” and “Peaches”.
2+
#Display the list.
3+
fruit1 = ['Apples','Pears','Oranges','Peaches']
4+
print fruit1 ,'\n'
5+
6+
#Ask the user for another fruit and add it to the end of the list.
7+
#Display the list.
8+
new1 = raw_input("Please add a new fruit to the list:\n")
9+
fruit1.append(new1)
10+
print fruit1 ,'\n'
11+
12+
#Ask the user for a number and display the number back to the user and
13+
#the fruit corresponding to that number (on a 1-is-first basis).
14+
#Display the list.
15+
new2 = int(raw_input("Please choose a number from the list of fruit:\n"))
16+
print fruit1[new2] ,'\n'
17+
18+
#Add another fruit to the beginning of the list using “+” and display the list.
19+
new3 = raw_input("Please add a new fruit to the list:\n")
20+
fruit2 = [new3]
21+
fruit3 = fruit2 + fruit1
22+
print fruit3 ,'\n'
23+
24+
#Add another fruit to the beginning of the list using insert() and display the list.
25+
new4 = raw_input("Please add a new fruit to the list:\n")
26+
fruit3.insert(0, new4)
27+
print fruit3 ,'\n'
28+
29+
##Display all the fruits that begin with “P”, using a for loop.
30+
print ("All the fruits that begin with P:\n")
31+
for i in fruit3:
32+
if i[0] == 'P':
33+
print i + '\n'
34+
#Using the list(fruit3) created in series 1 :
35+
36+
37+
#Remove the last fruit from the list.Display the list.
38+
fruit4 = fruit3
39+
print ("Removing the last fruit from the list:\n")
40+
fruit4.remove(fruit4[-1])
41+
print fruit4
42+
43+
#Ask the user for a fruit to delete and find it and delete it.Display the list.
44+
new4 = raw_input("Please choose a fruit from the list to delete:\n")
45+
for i in fruit4:
46+
if i == new4:
47+
fruit4.remove(i)
48+
print fruit4 ,'\n'
49+
50+
#Ask the user for input displaying a line like “Do you like apples?”
51+
#For each fruit in the list (making the fruit all lowercase).
52+
#For each “no”, delete that fruit from the list.
53+
#For any answer that is not “yes” or “no”, prompt the user to answer with one of those two values (a while loop is good here):
54+
#Display the list.
55+
56+
#Remove extra copy
57+
fruit5 = fruit3
58+
for i in fruit5[:]:
59+
i =i.lower()
60+
61+
62+
63+
while True:
64+
new4 = raw_input('Do you like ' + i +' ? Please answer with a Yes or No\n' )
65+
66+
if new4 == 'Yes'or new4 == 'No':
67+
break
68+
if new4 == 'Yes':
69+
continue
70+
71+
else:
72+
i = i[0].upper() +i[1::]
73+
fruit5.remove(i)
74+
75+
print fruit5,'\n'
76+
77+
#Make a copy of the list and reverse the letters in each fruit in the copy.
78+
#Delete the last item of the original list. Display the original list and the copy.
79+
80+
81+
oring_fruit = fruit3[:]
82+
copy_fruit = fruit3[:]
83+
84+
for i in range(len(copy_fruit)):
85+
fruit6_reverse = []
86+
fruit6 = copy_fruit.pop(i)
87+
fruit6_reverse.extend(fruit6)
88+
fruit6_reverse.reverse()
89+
fruit6 = "".join(fruit6_reverse)
90+
copy_fruit.insert(i, fruit6)
91+
oring_fruit.remove(oring_fruit[-1])
92+
93+
print "Original List of Fruit: %s" % oring_fruit
94+
print "Copied List of Fruit: %s" % copy_fruit
95+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def rot13(s):
2+
print s
3+
from codecs import encode
4+
return s.encode('rot13')
5+
6+
7+
if __name__ == '__main__':
8+
9+
assert rot13('ZNTARGVP SEBZ BHGFVQR ARNE PBEARE') == 'MAGNETIC FROM OUTSIDE NEAR CORNER'
10+
print "All Tests Pass"
11+
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#Create a data structure with 2 elements (Name, Dollar Amount Donated)
2+
3+
donor_list = ['Mick Jagger','$500.00',
4+
'Jimmy Page','$200.00',
5+
'Robert Plant','$100.00',
6+
'Roger Daltry','$400.00',
7+
'Pete Townsend','$250.00',
8+
'Eric Clapton','$500.00',
9+
'Mick Jagger','$700.00',
10+
'Eric Clapton','$200.00',
11+
'Pete Townsend','$950.00',
12+
'Robert Plant','$800.00',
13+
'Mick Jagger','$400.00',
14+
'Roger Daltry','$750.00',
15+
'Pete Townsend','$750.00',
16+
'Eric Clapton','$900.00',
17+
'Mick Jagger','$500.00',
18+
'Robert Plant','$800.00',
19+
'Roger Daltry','$600.00',]
20+
21+
def write_thk_letrs(user_input2):
22+
#Write a letter thanking a donor#
23+
24+
print ("Dear %s. \n\nThank you for your generous contribution !\n\nYou Rock !\n\n" % (user_input2))
25+
return main()
26+
27+
28+
def thanks_note():
29+
user_input2 =raw_input('Please provide the full name of the donor, or type "list for a list of donors" :\n\n')
30+
31+
if user_input2 == 'list':
32+
tmp_list1= []
33+
tmp_list2= []
34+
i = ""
35+
tmp_list1 = donor_list[0::2]
36+
for i in tmp_list1:
37+
if i not in tmp_list2:
38+
tmp_list2.append(i)
39+
for x in tmp_list2:
40+
print ("\n" + x + "\n")
41+
return add_donor()
42+
43+
else:
44+
for d_name in donor_list:
45+
if d_name == user_input2:
46+
return write_thk_letrs(user_input2)
47+
48+
49+
def add_donor():
50+
user_input2 =raw_input('Please provide the full name of the donor, or type "list for a list of donors" :\n\n')
51+
for d_name in donor_list:
52+
53+
if d_name != user_input2:
54+
break
55+
56+
while True:
57+
user_input3 = raw_input("\n" + user_input2 + " is a new donor,and can be added to the donor list.\n " " \nWould you like"
58+
" to make a donation for " + user_input2 + " ?\n\nPlease answer 'Yes' or 'No' ")
59+
60+
if user_input3 == "No":
61+
main()
62+
63+
if user_input3 == "Yes":
64+
break
65+
66+
while True:
67+
user_input4 = raw_input('Enter the donation amount \n\n ')
68+
69+
#if user_input3 == 'menu':
70+
#return 'menu'
71+
try:
72+
user_input4 = float(user_input4)
73+
break
74+
75+
except ValueError:
76+
print 'Specified Donations must be a in a numeric format, renter amount.'
77+
78+
79+
user_input4 = "$"+str(user_input4)
80+
donor_list.extend([user_input2, user_input4])
81+
write_thk_letrs(user_input2)
82+
83+
def donor_report():
84+
85+
tmp_list3= []
86+
tmp_list4= []
87+
user_input5 =""
88+
i = ""
89+
tmp_list3 = donor_list[0::2]
90+
91+
print("\n\nDonor Name Total Amount Donated Number of Donations Average Donation\n" )
92+
for i in tmp_list3:
93+
if i not in tmp_list4:
94+
tmp_list4.append(i)
95+
for x in tmp_list4:
96+
print ("\n" + x + "\n")
97+
98+
def main():
99+
100+
101+
while True:
102+
user_input1 = ''
103+
user_input2 = ''
104+
user_input3 = ''
105+
user_input4 = ''
106+
user_input4 = ''
107+
108+
user_input1 = raw_input('Welcome to the Donations Support Program\n\n'
109+
'Please enter a 1 to Send a Thank You Note \n\n'
110+
'Please enter a 2 to Create a Report \n\n'
111+
'Please enter a 3 to exit this project \n\n')
112+
113+
114+
if user_input1 == '1':
115+
#print("Send a Thank You Note")
116+
return thanks_note()
117+
118+
119+
if user_input1 == '2':
120+
#print("Create a Report")
121+
return donor_report()
122+
123+
124+
if user_input1 == '3':
125+
print ("Exiting this Program")
126+
break
127+
128+
129+
130+
if __name__ == '__main__':
131+
main()
132+
133+

0 commit comments

Comments
 (0)