diff --git a/students/JohnRudolph/session4/sherlock_small.txt b/students/JohnRudolph/session4/sherlock_small.txt new file mode 100644 index 0000000..dad12e2 --- /dev/null +++ b/students/JohnRudolph/session4/sherlock_small.txt @@ -0,0 +1,16 @@ +One night--it was on the twentieth of March, 1888--I was +returning from a journey to a patient (for I had now returned to +civil practice), when my way led me through Baker Street. As I +passed the well-remembered door, which must always be associated +in my mind with my wooing, and with the dark incidents of the +Study in Scarlet, I was seized with a keen desire to see Holmes +again, and to know how he was employing his extraordinary powers. +His rooms were brilliantly lit, and, even as I looked up, I saw +his tall, spare figure pass twice in a dark silhouette against +the blind. He was pacing the room swiftly, eagerly, with his head +sunk upon his chest and his hands clasped behind him. To me, who +knew his every mood and habit, his attitude and manner told their +own story. He was at work again. He had risen out of his +drug-created dreams and was hot upon the scent of some new +problem. I rang the bell and was shown up to the chamber which +had formerly been in part my own. diff --git a/students/susanRees/LighteningTalkFiles/lighteningTalk.py b/students/susanRees/LighteningTalkFiles/lighteningTalk.py new file mode 100644 index 0000000..39867b6 --- /dev/null +++ b/students/susanRees/LighteningTalkFiles/lighteningTalk.py @@ -0,0 +1,69 @@ +#################### +## import modules ## +#################### + +# the program opens the workbook by importing the openpyxl module and calling +# the openpyxl.load_workbook() function. +import openpyxl as op +wb = openpyxl.load_workbook('surveyData.xlsx') + +def get_age_groups(my_sheet, my_column): + # calls the get_sheet_by_name function to get the worksheet object + sheet = wb.get_sheet_by_name(my_sheet) + # Use the cell() sheet method with row and column keyword arguments + # to pull values from all cells in one column. puts them into a tuple. + rawAgeData = sheet.columns[my_column] + for cellObj in sheet.columns[my_column]: + print(cellObj.value) + # puts them in order + ageDataOrdered = [sorted(rawAgeData)] + # Using a for loop? counts the total number of entries, creates dictionary + # with unique entries (age) as keys, and the number of times each entry + # appears as value? + ageGroups = {} + for items in ageDataOrdered: + if items == items: + ageGroups = {counts(items)} + # remove duplicate items?? use itertools + else: + ageGroups = {counts(items)} + # in new dictionary? iterates through dict values and divides by total + # number of entries to provide the percentage (new value) of the whole that + # each unique entry group (keys) represents + # sorts entries (keys) by percentage (value) to see the order of importance + for keys, values in (ageGroups.items()): + numAges = len(keys) + percentAge = int(values/numAges) + finalNums = {percentAge} + sorted(finalNums, percentAge) + +# starts program +if __name__ == '__main__': + my_script.main() + +my_sheet = 'path to excel sheet' + +# Displays them in a pie (lol) chart or bar graph of some sort? +# example from automate the borimg stuff below. +# import openpyxl +# wb = openpyxl.Workbook() +# sheet = wb.get_active_sheet() +# for i in range(1, 11): # create some data in column A +# sheet['A' + str(i)] = i + +# refObj = openpyxl.charts.Reference(sheet, (1, 1), (10, 1)) + +# seriesObj = openpyxl.charts.Series(refObj, title='First series') + +# chartObj = openpyxl.charts.PieChart() # can also use BarChart +# chartObj.append(seriesObj) +# chartObj.drawing.top = 50 # set the position +# chartObj.drawing.left = 100 +# chartObj.drawing.width = 300 # set the size +# chartObj.drawing.height = 200 + +# sheet.add_chart(chartObj) +# wb.save('sampleChart.xlsx') + +# convert this program to require user input (which column do you want?) or to +# run on all columns automatically? diff --git a/students/susanRees/LighteningTalkFiles/lighteningTalkPandas.py b/students/susanRees/LighteningTalkFiles/lighteningTalkPandas.py new file mode 100644 index 0000000..20a70b2 --- /dev/null +++ b/students/susanRees/LighteningTalkFiles/lighteningTalkPandas.py @@ -0,0 +1,42 @@ +# Imports pandas +# reads the spreadsheet +# pops the "Age" column out +# uses .value_counts to group ages together and +# sorts them in ascending order according to frequency of occurance + +import pandas as pd +df = pd.read_excel("surveyData.xlsx") +ages = df.pop("Age") +print(ages.value_counts(normalize=True, sort=True, ascending=False, bins=None, dropna=True)) + + +# pandas.series.value_counts +# series.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True) + +# Returns object containing counts of unique values. + +# The resulting object will be in descending order so that the first +# element is the most frequently-occurring element. Excludes NA values +# by default. + +# Parameters: + +# normalize : boolean, default False +# If True then the object returned will contain the relative +# frequencies of the unique values. + +# sort : boolean, default True +# Sort by values + +# ascending : boolean, default False +# Sort in ascending order + +# bins : integer, optional +# Rather than count values, group them into half-open bins, a +# convenience for pd.cut, only works with numeric data + +# dropna : boolean, default True +# Don’t include counts of NaN. + +# Returns: +# counts : Series diff --git a/students/susanRees/LighteningTalkFiles/surveyData.xls b/students/susanRees/LighteningTalkFiles/surveyData.xls new file mode 100644 index 0000000..a002ce6 Binary files /dev/null and b/students/susanRees/LighteningTalkFiles/surveyData.xls differ diff --git a/students/susanRees/LighteningTalkFiles/surveyData.xlsx b/students/susanRees/LighteningTalkFiles/surveyData.xlsx new file mode 100644 index 0000000..8254fec Binary files /dev/null and b/students/susanRees/LighteningTalkFiles/surveyData.xlsx differ diff --git a/students/susanRees/session02/PrintGrid.py b/students/susanRees/session02/PrintGrid.py index f8c8fbe..dba0eb0 100644 --- a/students/susanRees/session02/PrintGrid.py +++ b/students/susanRees/session02/PrintGrid.py @@ -21,23 +21,38 @@ def print_column(): print_column() print_row() - print_grid(10) def second_grid(x, y): - n = (y-1) - for n in range(0, n): - def print_rows(): + n = (x + 1) + m = (n - 1) + for m in range(0, m): + def print_row(): print('+', end=' '), print('-' * y, end=' '), - print_rows() - print('+') - def print_columns(): + def print_rows(): + n = (x + 1) + m = (n - 1) + for m in range (0, m): + print_row() + def print_column(): print('|', end=' '), print(' ' * y, end=' '), - print_columns() - print('|') + def print_columns(): + n = (x + 1) + m = (n - 1) + for m in range (0, m): + print_column() + print_rows() + print('+') + def print_mult_columns(): + n = (y + 1) + m = (n - 1) + for m in range (0, m): + print_columns() + print('|') + print_mult_columns() print_rows() print('+') -second_grid(3, 4) +second_grid(4, 10) diff --git a/students/susanRees/session03/Lists.py b/students/susanRees/session03/Lists.py index cd42047..c5eb81c 100644 --- a/students/susanRees/session03/Lists.py +++ b/students/susanRees/session03/Lists.py @@ -95,16 +95,16 @@ # Make a copy of the original list -backwards_fruits = fruits[0:-1] +backwards_fruits = fruits[:] # reverse the letters in each fruit in the copy. -# for bwards in backwards_fruits: - -# print(backwards_fruits) +for item in backwards_fruits[:]: + bward_item = item[::-1] + backwards_fruits.append(bward_item) # Delete the last item of the original list. -# fruits.pop(-1) +fruits.pop(-1) # Display the original list and the copy. -# print(fruits) -# print(backwards_fruits) +print(fruits) +print(backwards_fruits) diff --git a/students/susanRees/session04/DictionaryLab.py b/students/susanRees/session04/DictionaryLab.py index e8f93b5..d04f381 100644 --- a/students/susanRees/session04/DictionaryLab.py +++ b/students/susanRees/session04/DictionaryLab.py @@ -1,51 +1,72 @@ # Create a dictionary containing “name”, “city”, and “cake” # for “Chris” from “Seattle” who likes “Chocolate”. -dict = {'name': "Chris", 'city': "Seattle", 'cake': "Chocolate"} +stuff = {'name': "Chris", 'city': "Seattle", 'cake': "Chocolate"} # Display the dictionary. -print(dict) +print(stuff) # Delete the entry for “cake”. -dict.pop('cake') +stuff.pop('cake') # Display the dictionary. -print(dict) +print(stuff) # Add an entry for “fruit” with “Mango” and display the dictionary. -dict.update({'fruit': "Mango"}) +stuff.update({'fruit': "Mango"}) -print(dict) +print(stuff) # Display the dictionary keys. -print(dict.keys()) +print(stuff.keys()) # Display the dictionary values. -print(dict.values()) +print(stuff.values()) # Display whether or not “cake” is a key in the dictionary (i.e. False) (now). -print("True" if 'cake' in dict else "False") +print("True" if 'cake' in stuff else "False") # Display whether or not “Mango” is a value in the dictionary (i.e. True). -print("True" if "Mango" in dict.values() else "False") +print("True" if "Mango" in stuff.values() else "False") # Using the dictionary from item 1: # Make a dictionary using same keys but with the number of ‘t’s in each value. -# Not sure I understand the assingment... +stuff = {'name': "Chris".count("t"), 'city': "Seattle".count("t"), 'cake': "Chocolate".count("t")} +print(stuff) # Create sets s2, s3 and s4 containing numbers from 0-20, divisible 2, 3 and 4. -s2 = set([1:20]) -s3 = set([1:20]) -s4 = set([1:20]) +s2 = set([x for x in range(0, 20) if x % 2 == 0]) +s3 = set([x for x in range(0, 20) if x % 3 == 0]) +s4 = set([x for x in range(0, 20) if x % 4 == 0]) # Display the sets. +print(s2) +print(s3) +print(s4) # Display if s3 is a subset of s2 (False) +if s3.issubset(s2): + print(True) +else: + print(False) # and if s4 is a subset of s2 (True). +if s4.issubset(s2): + print(True) +else: + print(False) -# Create a set with the letters in ‘Python’ and add ‘i’ to the set. +# Create a set with the letters in ‘Python’ +python = set(["p", "y", "t", "h", "o", "n"]) + +#add ‘i’ to the set. +python.update(["i"]) +print(python) # Create a frozenset with the letters in ‘marathon’ +marathon = frozenset(["m", "a", "r", "a", "t", "h", "o", "n"]) +print(marathon) -# display the union and intersection of the two sets. \ No newline at end of file +# display the union and intersection of the two sets. +print(marathon.union(python)) +print(marathon.intersection(python)) \ No newline at end of file diff --git a/students/susanRees/session05/comprehensions.py b/students/susanRees/session05/comprehensions.py new file mode 100644 index 0000000..958053f --- /dev/null +++ b/students/susanRees/session05/comprehensions.py @@ -0,0 +1,36 @@ +feast = ['lambs', 'sloths', 'orangutans', 'breakfast cereals', 'fruit bats'] +comprehension = [delicacy.capitalize() for delicacy in feast] +print(comprehension[0]) +print(comprehension[2]) + +comp = [delicacy for delicacy in feast if len(delicacy) > 6] +print(len(feast)) +print(len(comp)) + +list_of_tuples = [(1, 'lumberjack'), (2, 'inquisition'), (4, 'spam')] +comprehension = [skit * number for number, skit in list_of_tuples] +print(comprehension[0]) +print(len(comprehension[2])) + +eggs = ['poached egg', 'fried egg'] +meats = ['lite spam', 'ham spam', 'fried spam'] +comprehension = ['{0} and {1}'.format(egg, meat) for egg in eggs for meat in meats] +print(len(comprehension)) +print(comprehension[0]) + +comprehension = {x for x in 'aabbbcccc'} +print(comprehension) + +dict_of_weapons = {'first': 'fear', 'second': 'surprise', 'third':'ruthless efficiency', 'forth':'fanatical devotion', 'fifth': None} +dict_comprehension = {k.upper(): weapon for k, weapon in dict_of_weapons.iteritems() if weapon} +print('first' in dict_comprehension) +print('FIRST' in dict_comprehension) +print(len(dict_of_weapons)) +print(len(dict_comprehension)) + +#count_evens([2, 1, 2, 3, 4]) == 3 +#count_evens([2, 2, 0]) == 3 +#count_evens([1, 3, 5]) == 0 + +#def count_evens(nums): +# one_line_comprehension_here diff --git a/students/susanRees/session05/exceptions.py b/students/susanRees/session05/exceptions.py new file mode 100644 index 0000000..aef7263 --- /dev/null +++ b/students/susanRees/session05/exceptions.py @@ -0,0 +1,12 @@ +# Create a wrapper function, safe_input() +# returns None rather rather than raising the exceptions EOFError or KeyboardInterrupt +# when user enters ^C for Keyboard Interrupt, or ^D (^Z on Windows) for End Of File. + +def safe_input(): + try: + input("Type something here") + except (EOFError, KeyboardInterrupt): + return None + else: + print("Thanks.") +safe_input() diff --git a/students/susanRees/session06/exceptions.py b/students/susanRees/session05/pathFileProcessing.py similarity index 100% rename from students/susanRees/session06/exceptions.py rename to students/susanRees/session05/pathFileProcessing.py diff --git a/students/susanRees/session05/testing.py b/students/susanRees/session05/testing.py new file mode 100644 index 0000000..e69de29 diff --git a/students/susanRees/session06/functions.py b/students/susanRees/session06/functions.py new file mode 100644 index 0000000..e69de29 diff --git a/students/susanRees/session06/trapezoidal.py b/students/susanRees/session06/trapezoidal.py new file mode 100644 index 0000000..e69de29 diff --git a/students/susanRees/session07/htmlRenderer.py b/students/susanRees/session07/htmlRenderer.py new file mode 100644 index 0000000..e69de29 diff --git a/students/susanRees/session08/circleClass.py b/students/susanRees/session08/circleClass.py new file mode 100644 index 0000000..e69de29 diff --git a/students/susanRees/session08/sparseArray.py b/students/susanRees/session08/sparseArray.py new file mode 100644 index 0000000..e69de29 diff --git a/students/susanRees/session09/lambdaKeywordMagic.py b/students/susanRees/session09/lambdaKeywordMagic.py new file mode 100644 index 0000000..e69de29