diff --git a/Students/lascoli/session03/unfinished_mailroom_4.py b/Students/lascoli/session03/unfinished_mailroom_4.py new file mode 100644 index 00000000..dcc3237e --- /dev/null +++ b/Students/lascoli/session03/unfinished_mailroom_4.py @@ -0,0 +1,122 @@ +#Create a data structure with 2 elements (Name, Dollar Amount Donated) + +donor_db = [] +donor_db.append( ("Jimmy Page", [653772.32, 12.17]) ) +donor_db.append( ("Robert Plant", [877.33]) ) +donor_db.append( ("Roger Daltry", [663.23, 43.87, 1.32]) ) +donor_db.append( ("Pete Townsend", [1663.23, 4300.87, 10432.0]) ) +donor_db.append( ("Mick Jagger", [653772.32, 12.17]) ) + +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() + + diff --git a/Students/lascoli/session04/Dict_Set Lab.py b/Students/lascoli/session04/Dict_Set Lab.py new file mode 100644 index 00000000..6287bad1 --- /dev/null +++ b/Students/lascoli/session04/Dict_Set Lab.py @@ -0,0 +1,108 @@ +#Create a dictionary +dict_1 = {} +dict_1={'name':'Chris','city':'Seattle','cake':'Chocolate'} + +#Display the dictionary +dict_1 + +#Delete the entry for “cake”. +dict_1.pop('cake') + +#Add an entry for “fruit” with “Mango” and display the dictionary. +dict_1.setdefault('fruit', 'Mango') +#Display the dictionary keys +dict_1.keys() + +#Display the dictionary values +dict_1.keys() + +#Display whether or not “cake” is a key in the dictionary (i.e. False) (now). +'cake'in dict_1 + +#Display whether or not “Mango” is a value in the dictionary (i.e. True). +'Mango'in dict_1.values() + +#Using the dict constructor and zip, build a dictionary of numbers +#from zero to fifteen and the hexadecimal equivalent (string is fine). + +def gen_lists(): + + llist1 =[] + hlist1 =[] + n_list =[] + tmp_lists_dict ={} + + llist1 = range(1,16) + for i in llist1: + x = hex(i) + hlist1.append(x) + + n_list = zip(llist1,hlist1) + #return (n_list) + tmp_lists_dict = dict(n_list) + print (tmp_lists_dict) + + +gen_lists() + + +#Using the dictionary from item 1: Make a dictionary using the same keys but +#with the number of‘t’s in each value. + +dict_1={'name':'Chris','city':'Seattle','cake':'Chocolate'} +dict_2={} +list_1=[] +for a,b in dict_1.items(): + list_1.append((a,b.count('t'))) +dict_2 =dict(list_1) +print dict_2 + + +#Create sets set_2, set_3 and set_4 that contain numbers from zero through twenty, divisible 2, 3 and 4. + + +s_0 = set(range(21)) +set_2 = [] +set_3 = [] +set_4 = [] +for i in s_0: + if i % 2 == 0: + set_2.append(i) +set_2 = set(set_2) + +for i in s_0: + if i % 3 == 0: + set_3.append(i) +set_3 = set(set_3) + +for i in s_0: + if i % 4 == 0: + set_4.append(i) +set_4 = set(set_4) + + +#Display the sets. +print set_1 +print set_2 +print set_3 +print set_4 + +#Display if set_3 is a subset of set_2 (False) + +set(set_3).issubset(set_2) + +#if set_4 is a subset of set_2 (True) +set(set_4).issubset(set_2) + + +# Create a set with the letters in ‘Python’ and add ‘i’ to the set. +x = set("Python") +x.add("i") + +# Create a frozenset with the letters in ‘marathon’ +y = frozenset(“marathon”) + +# display the union and intersection of the two sets. +x.union(y) +x.intersection(y) + diff --git a/Students/lascoli/session04/safe_input.py b/Students/lascoli/session04/safe_input.py new file mode 100644 index 00000000..c4236bf4 --- /dev/null +++ b/Students/lascoli/session04/safe_input.py @@ -0,0 +1,10 @@ +"""Creating Wrapper Function Safe Input """ +def safe_input(msg): +"""Function is called when ^C or ^D occurs""" +try: + x = raw_input(user_action) +except (EOFError, KeyboardInterrupt): + return None +else: + return variaxble +if __name__ == "__main__": \ No newline at end of file