Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions Students/lascoli/session03/list_lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#Create a list that contains “Apples”, “Pears”, “Oranges” and “Peaches”.
#Display the list.
fruit1 = ['Apples','Pears','Oranges','Peaches']
print fruit1 ,'\n'

#Ask the user for another fruit and add it to the end of the list.
#Display the list.
new1 = raw_input("Please add a new fruit to the list:\n")
fruit1.append(new1)
print fruit1 ,'\n'

#Ask the user for a number and display the number back to the user and
#the fruit corresponding to that number (on a 1-is-first basis).
#Display the list.
new2 = int(raw_input("Please choose a number from the list of fruit:\n"))
print fruit1[new2] ,'\n'

#Add another fruit to the beginning of the list using “+” and display the list.
new3 = raw_input("Please add a new fruit to the list:\n")
fruit2 = [new3]
fruit3 = fruit2 + fruit1
print fruit3 ,'\n'

#Add another fruit to the beginning of the list using insert() and display the list.
new4 = raw_input("Please add a new fruit to the list:\n")
fruit3.insert(0, new4)
print fruit3 ,'\n'

##Display all the fruits that begin with “P”, using a for loop.
print ("All the fruits that begin with P:\n")
for i in fruit3:
if i[0] == 'P':
print i + '\n'
#Using the list(fruit3) created in series 1 :


#Remove the last fruit from the list.Display the list.
fruit4 = fruit3
print ("Removing the last fruit from the list:\n")
fruit4.remove(fruit4[-1])
print fruit4

#Ask the user for a fruit to delete and find it and delete it.Display the list.
new4 = raw_input("Please choose a fruit from the list to delete:\n")
for i in fruit4:
if i == new4:
fruit4.remove(i)
print fruit4 ,'\n'

#Ask the user for input displaying a line like “Do you like apples?”
#For each fruit in the list (making the fruit all lowercase).
#For each “no”, delete that fruit from the list.
#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):
#Display the list.

#Remove extra copy
fruit5 = fruit3
for i in fruit5[:]:
i =i.lower()



while True:
new4 = raw_input('Do you like ' + i +' ? Please answer with a Yes or No\n' )

if new4 == 'Yes'or new4 == 'No':
break
if new4 == 'Yes':
continue

else:
i = i[0].upper() +i[1::]
fruit5.remove(i)

print fruit5,'\n'

#Make a copy of the list and reverse the letters in each fruit in the copy.
#Delete the last item of the original list. Display the original list and the copy.


oring_fruit = fruit3[:]
copy_fruit = fruit3[:]

for i in range(len(copy_fruit)):
fruit6_reverse = []
fruit6 = copy_fruit.pop(i)
fruit6_reverse.extend(fruit6)
fruit6_reverse.reverse()
fruit6 = "".join(fruit6_reverse)
copy_fruit.insert(i, fruit6)
oring_fruit.remove(oring_fruit[-1])

print "Original List of Fruit: %s" % oring_fruit
print "Copied List of Fruit: %s" % copy_fruit

11 changes: 11 additions & 0 deletions Students/lascoli/session03/rot13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def rot13(s):
print s
from codecs import encode
return s.encode('rot13')


if __name__ == '__main__':

assert rot13('ZNTARGVP SEBZ BHGFVQR ARNE PBEARE') == 'MAGNETIC FROM OUTSIDE NEAR CORNER'
print "All Tests Pass"

133 changes: 133 additions & 0 deletions Students/lascoli/session03/unfinished_mailroom_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#Create a data structure with 2 elements (Name, Dollar Amount Donated)

donor_list = ['Mick Jagger','$500.00',
'Jimmy Page','$200.00',
'Robert Plant','$100.00',
'Roger Daltry','$400.00',
'Pete Townsend','$250.00',
'Eric Clapton','$500.00',
'Mick Jagger','$700.00',
'Eric Clapton','$200.00',
'Pete Townsend','$950.00',
'Robert Plant','$800.00',
'Mick Jagger','$400.00',
'Roger Daltry','$750.00',
'Pete Townsend','$750.00',
'Eric Clapton','$900.00',
'Mick Jagger','$500.00',
'Robert Plant','$800.00',
'Roger Daltry','$600.00',]

def write_thk_letrs(user_input2):
#Write a letter thanking a donor#

print ("Dear %s. \n\nThank you for your generous contribution !\n\nYou Rock !\n\n" % (user_input2))
return main()


def thanks_note():
user_input2 =raw_input('Please provide the full name of the donor, or type "list for a list of donors" :\n\n')

if user_input2 == 'list':
tmp_list1= []
tmp_list2= []
i = ""
tmp_list1 = donor_list[0::2]
for i in tmp_list1:
if i not in tmp_list2:
tmp_list2.append(i)
for x in tmp_list2:
print ("\n" + x + "\n")
return add_donor()

else:
for d_name in donor_list:
if d_name == user_input2:
return write_thk_letrs(user_input2)


def add_donor():
user_input2 =raw_input('Please provide the full name of the donor, or type "list for a list of donors" :\n\n')
for d_name in donor_list:

if d_name != user_input2:
break

while True:
user_input3 = raw_input("\n" + user_input2 + " is a new donor,and can be added to the donor list.\n " " \nWould you like"
" to make a donation for " + user_input2 + " ?\n\nPlease answer 'Yes' or 'No' ")

if user_input3 == "No":
main()

if user_input3 == "Yes":
break

while True:
user_input4 = raw_input('Enter the donation amount \n\n ')

#if user_input3 == 'menu':
#return 'menu'
try:
user_input4 = float(user_input4)
break

except ValueError:
print 'Specified Donations must be a in a numeric format, renter amount.'


user_input4 = "$"+str(user_input4)
donor_list.extend([user_input2, user_input4])
write_thk_letrs(user_input2)

def donor_report():

tmp_list3= []
tmp_list4= []
user_input5 =""
i = ""
tmp_list3 = donor_list[0::2]

print("\n\nDonor Name Total Amount Donated Number of Donations Average Donation\n" )
for i in tmp_list3:
if i not in tmp_list4:
tmp_list4.append(i)
for x in tmp_list4:
print ("\n" + x + "\n")

def main():


while True:
user_input1 = ''
user_input2 = ''
user_input3 = ''
user_input4 = ''
user_input4 = ''

user_input1 = raw_input('Welcome to the Donations Support Program\n\n'
'Please enter a 1 to Send a Thank You Note \n\n'
'Please enter a 2 to Create a Report \n\n'
'Please enter a 3 to exit this project \n\n')


if user_input1 == '1':
#print("Send a Thank You Note")
return thanks_note()


if user_input1 == '2':
#print("Create a Report")
return donor_report()


if user_input1 == '3':
print ("Exiting this Program")
break



if __name__ == '__main__':
main()