Skip to content
Open
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
2 changes: 1 addition & 1 deletion Examples/Session05/test_pytest_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def add(a, b):
test_data = [ ( ( 2, 3), 5),
( (-3, 2), -1),
( ( 2, 0.5), 2.5),
( ( "this", "that"), "this that"),
( ( "this", "that"), "thisthat"),
( ( [1,2,3], [6,7,8]), [1,2,3,6,7,8]),
]

Expand Down
Empty file.
15 changes: 15 additions & 0 deletions Students/bvanderlugt/session01/break_me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def name_break():
return a


def type_break():
return 'foo' / 2


def syntax_break():
retun 'bar'


def attribute_break():
a = 22
return a.foo()
61 changes: 61 additions & 0 deletions Students/bvanderlugt/session01/notes_01
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

Class 01
---
1/08/14
---

*Questions*
-Office hours? A: Sat morning via interwebz
-Reviewing HW material

type(size) means "what is the type of the value currently held in
variable 'size'"

Keywords = special reserved words
Built-in function = just a function that has been defined
'out of the box'
-print is weird...a keyword in python2 and a built-in variable in
python

Object Oriented Programming
-"interveiw q": what is oop?
- the shitt answer is: "inherited polymorphism"
-the thing that makes it valuable? objects gibe you virtual entities that you
can abstract like real objects
- the car example: car object, and driver object. You can model meaningful
intuitive objects of the real world. tired driver, shitty stopping car
- interesting aspects come from "emergent" interactions...the relationship
between objects revealing relationships

---

Base off question: "How to determine when your objects are
scoped appropriately"
---

**hueristic** rule of thumb for breaking up code:

*single responsibility principle*: A unit of code should do one thing and
do it well...a function, should do one thing and do it well...a package,
should do one thing, and do it well...
ex. a method: "render and print" -- bad, do one thing
good -- "render" and then "print"

---

encapsulation = a method that keeps you from messing with things you
shouldn't mess with

method is bound to an object
function is a block a code you can call that returns a value

dir(something) = how you figure out the methods associated with anything

double underscore thing double underscore = special methods for contexts

---

Housekeeping
---


36 changes: 36 additions & 0 deletions Students/bvanderlugt/session01/square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# square one
def square():
segment1 = ("+" + "-" * 4) * 2 + "+"
segment2 = ("|" + " " * 4) * 2 + "|"
for i in range(1, 12):
if i == 1 or i == 6 or i == 11:
print segment1
else:
print segment2


# print_grid
# add some kind of half-ass scaling
def print_grid(n):
# scale the dashes to n, subtract out the +'s
segment1 = ("+" + "-" * (n - 3)) * 2 + "+"
segment2 = ("|" + " " * (n - 3)) * 2 + "|"
# every five lines print segment one
for i in range(0, n):
if i % 5 == 0:
print segment1
else:
print segment2


# n by n
def n_grid(x, y):
# scale both segment lengths to x
segment1 = ("+" + "-" * (x - 3)) * 2 + "+"
segment2 = ("|" + " " * (x - 3)) * 2 + "|"
# scale i to y
for i in range(0, y):
if i % 5 == 0:
print segment1
else:
print segment2
18 changes: 18 additions & 0 deletions Students/bvanderlugt/session02/ack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def ack(m, n):
"""Returns the ackerman function of two numbers."""
if m < 0 or n < 0:
return None
if m == 0:
return n + 1
if m > 0 and n == 0:
return ack(m-1, 1)
if m > 0 and n > 0:
return ack(m-1, ack(m, n-1))


if __name__ == '__main__':
assert ack(0, 0) == 1
assert ack(0, 1) == 2
assert ack(0, 2) == 3
assert ack(0, 4) == 5
print "All tests pass"
15 changes: 15 additions & 0 deletions Students/bvanderlugt/session02/funky_bools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# also can do
# if not i % 3:
# print "some shit"


def fizz_buzz():
for i in range(1, 101):
if i % 3 == 0:
print "Fizz"
if i % 5 == 0:
print "Buzz"
else:
print(i)


27 changes: 27 additions & 0 deletions Students/bvanderlugt/session02/hw_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def lotr(n):
s = ""
if n % 3 == 0:
s += "Fizz"
if n % 5 == 0:
s += "Buzz"
if n % 7 == 0:
s += "Frodo"
if n % 11 == 0:
s += "Bilbo"
if n % 13 == 0:
s += "Gandalf"
if len(s) == 0:
return n
return s


for i in range(1, 101):
print lotr(i)

# sqrt
def sqrootz(x1, x2, y1, y2):
dist = (x1-x2)**2 + (y1-y2)**2
return dist



93 changes: 93 additions & 0 deletions Students/bvanderlugt/session02/notes02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Intro to Python 02
1/15/2015

Note: Github is not letting me push files w/o password.
Da hell is going on with my ssh?

**Q from HW:** validating raw_input()

pass: tells python there is an empty block. similar to:
function() {
}
Nothing betwee the mustaches, in python we dont have curly whirly
bars so we use pass!

things that make code non-reusable: calling sys.exit(), this command
breaks out of the interpreter

switch is actuallly pretty tricky, so it maybe is a good idea to
drop it from Python. Switch statements have 'fallthrough' and will
return multiple cases, hence the need for a break. In C, 'bless its
heart', there break is not manditory and fallthrough has lead to tons
of bugs, in C#, break is mandatory and is just noise. Not compelling
reasons for switch.

+ "Premature optimization is the root of all evil." - Donald Knuth

+ "There are two ways to make a software design: so simple that there are obviously no deficiencies, and so complex that there are no obvious deficiencies." - C. A. R. Hoare

+ "O(n^2) is too slow. Less than O(n^2) is fast enough." - Mickey Phoenix

Tuples are immutable, lists are mutable

Tuple is made with '()', list is made with '[]'

**idomatic python** tuples are more idiomatic when you do not want
your user to change something, you *can* use a list, but a tuple
explains your intention clearer.

**bad error messages** are a window into the working of Python.
Use errors to learn about Python.

ex. 'int' object is not iterable

**idiomatic python** swap in python foo, bar == bar, foo

play with this for a bit:

bob = (4,)
bob = (4,2)
bob , ted = ()
bob = ()

Mickey's fizzbuzz:

# bad because less readable
# if not n % 3:
# evals to 0 == False

def fizz_buzz(n):
if n % 3 == 0 and n % 5 == 0:
return "FizzBuzz"
if n % 3 == 0:
return "Fizz"
if n % 5 == 0:
return "Buzz"
return n

for i in range(1,101):
print fizz_buzz(i)

*note* on return in iPython, the Out syntax for ipython shows side
effects from functions

**Compare to my fizz_buzz**

def fizz_buzz():
for i in range(1, 101): # my loop is inside of function
if i % 3 == 0:
print "Fizz" # I used print in function, but Mickey said
# print is hard to debug
if i % 5 == 0:
print "Buzz"
else: # Mickey used the behavoir of return to
# to go through conditions, rather than
# call else, he ran return on the last
# condition
print(i)

I really like specifying the function outside of the for each loop.
using return in the funciton call, and print in the for loop.
I like how the return breaks the function, so there is no need for
else.

8 changes: 8 additions & 0 deletions Students/bvanderlugt/session02/series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def fibonacci(n):
"""Return the nth finonacci value."""
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result
55 changes: 55 additions & 0 deletions Students/bvanderlugt/session03/list_lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python


def fruit_list():
fruit = ["Apples", "Pears", "Oranges", "Peaches"]
print "existing fruit basket: " + str(fruit)
newFruit = str(raw_input("Enter a fruit to add to the basket: "))
fruit.append(newFruit)
print fruit
fruitIndex = int(raw_input("Enter fruit index: "))
print fruit[fruitIndex-1]
fruit = ["Grapefruit"] + fruit
fruit.insert(0, "kiwi")
print fruit
return fruit


for i in fruit_list():
if i[0] == "P":
print i



def fruit_two():
fruit = fruit_list()
print fruit
del fruit[-1]
print fruit
fruitDel = raw_input("Choose fruit to delete: ")
dubFruit = fruit*2
print "dub fruit is: "
print dubFruit

while fruitDel in dubFruit:
del dubFruit[dubFruit.index(fruitDel)]

print "after deletion, dub fruit: "
print dubFruit


def fruit_three():
fruit = fruit_list()
likeFruit = ""

for i in fruit:

while likeFruit not in ("yes", "no"):
likeFruit = raw_input("Do you like %s %s" % (i, "?"))

if likeFruit == "no":
del fruit[fruit.index(i)]

fruit_three()


13 changes: 13 additions & 0 deletions Students/bvanderlugt/session03/mailroom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
donors = {'Bob Lawbla': [10, 20, 30], 'Steve Bee': [2],
'Eric Smutz': [10, 30], 'Linda Hannigan': [30, 5],
'Katie Shmatie': [1, 3, 9]}

def mailroom():
response = ""
while not response.lower() == 'send a thank you' or not response.lower() == 'create a report':
response = raw_input("Would you like to send a thank you or create a report?")




mailroom()
Empty file.
Loading