Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.
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
24 changes: 24 additions & 0 deletions students/kegan/orientation/2017 09 27 Orientation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GitHub: https://github.com/UWPCE-PythonCert/IntroPython-2017
Slack: https://python2017-fall.slack.com/messages/D79UJS87M/
Google Group: https://groups.google.com/forum/#!forum/programming-in-python

**PIP
pip looks on internet for the package you specified on pypi
use the following command to to install package into the libraries python[version] (as opposed to whichever python version pip uses)
python[?version] -m pip_package

**EXECUTABLE
to make a python program an executable, put the following at the top of the file:
#!/usr/bin/env python[?version]
and run the following from the terminal where hello.py lives
chmod +x [python file]
then run it using
./[python file]

**IPYTHON
from ipython, you can run a python file by typing
run [name of file]

**SUBLIME
command+shift+p to open package
control package: install package
2 changes: 2 additions & 0 deletions students/kegan/session01/2017 10 03 Session 1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
questions:
1) any advantage to using del versus just reassigning or ignoring the variable?
49 changes: 49 additions & 0 deletions students/kegan/session01/break_me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
author@kathrynegan

Causes and catches NameError, AttributeError,
and TypeError in code and prints message if
error was successfully generated.
SyntaxError code included and commented out.
"""


def cause_name_error():
try:
print(name)
except NameError:
print('Successful NameError')
return
print('No NameError')


def cause_type_error():
try:
string = 'string'
string += 1
except TypeError:
print('Successful TypeError')
return
print('No TypeError')


def cause_attribute_error():
class ErrorProne:
def __init__(self):
self.value1 = 1
try:
error = ErrorProne()
print(error.value2)
except AttributeError:
print('Successful AttributeError')
return
print('No AttributeError')


cause_name_error()
cause_type_error()
cause_attribute_error()

# cause syntax error
# while True
# print('broken')
51 changes: 51 additions & 0 deletions students/kegan/session02/2017 10 10 Session 2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Session 02

git fetch copies all the upstream stuff locally but does not merge, then user must specify git merge to merge local and upstream versions

the pull request will always point to the latest version of repo

git will not track directories, only files

touch readme.txt will create a file called readme.txt

git add makes git “pay attention” to the file (track in repo)

changing a file after staging it will mean the changes won’t appear in the commit - the file must be staged again post-changes

don’t use eval or exec
- these evaluate python code as a text string
- advice is to not use these because it can enable injection of malicious code (e.g. in web app user input)

assert (expression|function) is (value|boolean)

////Lightning Talks////

SQLAlchemy

1) establish dataset
db = create_engine(‘adatabase.db’)
# open connection to database
# the resulting object has methods specific to the type of database
metadata = BoundMetaData(db)
# create an object that knows what the columns of the data are, what types of data they contain, etc.
# used to recreate analogous data structures in python
user = Table(‘users’, metadata, autolaod=True)
# figure out automatically what the table looks like

2) building sql statements
main idea: create sql statement objects and operate on those with python modules
e.g.
users.select()
users.insert()
join(table1, table2).select()
outerjoin(table1, table2).select()

3) map objects to the database
create an empty class to serve as a data class and map data tables onto empty data classes which take on correct column names and types
create a session object to keep track of data classes
select (load) data from database into data class
flush the session to push changes to the database

//////////////////

print(‘string’, end=‘’) make the end an empty string instead of a newline
14 changes: 14 additions & 0 deletions students/kegan/session02/fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Kathryn Egan

classic fizzbuzz program
"""
for i in range(1, 101):
output = ''
if i % 3 == 0:
output += 'Fizz'
if i % 5 == 0:
output += 'Buzz'
if not output:
output = i
print(output)
78 changes: 78 additions & 0 deletions students/kegan/session02/print_grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
Kathryn Egan

Prints a row x column grid consisting
of this square:
* - - - - *
| |
| |
| |
| |
* - - - - *
"""
import argparse


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'rows', help='number of rows to print between 1 and 10',
type=int, choices=range(1, 11))
parser.add_argument(
'columns', help='number of columns to print between 1 and 10',
type=int, choices=range(1, 11))
args = parser.parse_args()
grid = build_grid(args.rows, args.columns)
print(grid)


def build_grid(rows, columns):
""" Builds row x column grid.
Args:
rows (int) : number of rows
columns (int) : number of columns
Returns:
str : row x column grid
"""
grid = []
for __ in range(rows):
grid.append(print_horizontal(columns))
for __ in range(4):
grid.append(print_vertical(columns))
grid.append(print_horizontal(columns))
grid = '\n'.join(grid)
return grid


def print_horizontal(columns):
""" Returns a horizontal component of grid.
Args:
columns (int) : number of columns
Returns;
str : horizontal component of grid
"""
string = '*'
for __ in range(columns):
for __ in range(4):
string += ' -'
string += ' *'
return string


def print_vertical(columns):
""" Returns a vertical component of grid.
Args:
columns (int) : number of columns
Returns;
str : vertical component of grid
"""
string = '|'
for __ in range(columns):
for __ in range(9):
string += ' '
string += '|'
return string


if __name__ == '__main__':
main()
84 changes: 84 additions & 0 deletions students/kegan/session02/series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
Kathryn Egan

Computes Fibonacci, Lucas, and arbitrary series with
a given first and second base case to the nth value.
N is an ordinal starting at 1.
"""


def fibonacci(n):
""" Returns the nth value in the Fibonacci series.
Args:
n (int) : nth value to compute
Returns:
int : current value
"""
if n == 1:
return 0
if n == 2:
return 1
return fibonacci(n - 2) + fibonacci(n - 1)


def lucas(n):
""" Returns the nth value in the Lucas series.
Args:
n (int) : nth value to compute
Returns:
int : current value
"""
if n == 1:
return 2
if n == 2:
return 1
return lucas(n - 2) + lucas(n - 1)


def sum_series(n, base0, base1):
""" Returns the nth value in an arbitrary series with
given base cases.
Args:
n (int) : nth value to compute
base0 (int) : value of first in series
base1 (int) : value of second in series
Returns:
int : current value
"""
if n == 1:
return base0
if n == 2:
return base1
return (
sum_series(n - 2, base0, base1) +
sum_series(n - 1, base0, base1))


def test(module, solutions, **kwargs):
""" Tests given module against a solution.
Assumes kwargs will have base0 and base1 if
sum_series is passed.
Args:
module (function) : module to test
solutions (list ints) : solutions as a list of ints
kwargs (dict) : optional base0 and base1 args for sum_series
"""
if not kwargs:
for i in range(len(solutions)):
assert module(i + 1) == solutions[i]
elif 'base0' in kwargs and 'base1' in kwargs:
for i in range(len(solutions)):
answer = module(i + 1, kwargs['base0'], kwargs['base1'])
assert answer == solutions[i]
print('Could not test ' + str(module))


real_fib = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
real_lucas = [2, 1, 3, 4, 7, 11, 18, 29]

test(fibonacci, real_fib)
test(lucas, real_lucas)
test(sum_series, real_fib, base0=0, base1=1)
test(sum_series, real_lucas, base0=2, base1=1)

print("Passed all tests")
6 changes: 6 additions & 0 deletions students/kegan/session03/2017 10 17 session 03 notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
2017 10 17 Session 03

Separation of Concerns: better to have a module produce content that is returned to a higher level function than to output that content itself

Interning: python uses the same id for integers through about 300

6 changes: 6 additions & 0 deletions students/kegan/session03/ThankYous/Benedict Cumberbatch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dear Benedict Cumberbatch,
Thank you for your generous gift of $200,000. Your donation will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.

Regards,
Bungelina Bigglesnorf
Chairwoman, Miuvenile Care
6 changes: 6 additions & 0 deletions students/kegan/session03/ThankYous/Billy Neighbor.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dear Billy Neighbor,
Thank you for your generous gifts of $0.54, $0.01 and $0.25. Your donations, totalling $0.80, will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.

Regards,
Bungelina Bigglesnorf
Chairwoman, Miuvenile Care
6 changes: 6 additions & 0 deletions students/kegan/session03/ThankYous/Dad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dear Dad,
Thank you for your generous gifts of $20 and $5. Your donations, totalling $25, will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.

Regards,
Bungelina Bigglesnorf
Chairwoman, Miuvenile Care
6 changes: 6 additions & 0 deletions students/kegan/session03/ThankYous/Donald Trump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dear Donald Trump,
Thank you for your generous gift of $2.81. Your donation will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.

Regards,
Bungelina Bigglesnorf
Chairwoman, Miuvenile Care
6 changes: 6 additions & 0 deletions students/kegan/session03/ThankYous/Elon Musk.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dear Elon Musk,
Thank you for your generous gifts of $10,000, $150,000 and $100,000. Your donations, totalling an incredible $260,000, will go towards feeding homeless kittens in Seattle. From the bottom of our hearts, we at Miuvenile Care thank you.

Regards,
Bungelina Bigglesnorf
Chairwoman, Miuvenile Care
Loading