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
Empty file.
10 changes: 10 additions & 0 deletions Students/Lottsfeldt_Erik/Session01/monkey_trouble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def monkey_trouble(a_smile, b_smile):
if a_smile and b_smile:
return True
if not a_smile and not b_smile:
return True
return False
## The above can be shortened to:
## return ((a_smile and b_smile) or (not a_smile and not b_smile))
## Or this very short version (think about how this is the same as the above)
## return (a_smile == b_smile)
65 changes: 65 additions & 0 deletions Students/Lottsfeldt_Erik/Session01/print_grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Chris' solution to the week 1 homework problem.

Note that we hadn't talked about loops yet, so this is a solution with no
loops.

Note also that there is more than one way to skin a cat -- or code a function
"""
def print_grid(size):

"""
print a 2x2 grid with a total size of size

:param size: total size of grid -- it will be rounded if not one more than
a multiple of 2
"""
number = 2
box_size = int((size-1) // 2) # size of one grid box
print "box_size:", box_size
# top row
+ top = ('+ ' + '- ' * box_size) * number + '+' + '\n'
+ middle = ('| ' + ' ' * 2 * box_size) * number + '|' + '\n'
+
+ row = top + middle*box_size
+
+ grid = row*number + top
+
+ print grid
+
+
+def print_grid2(number, size):
+ """
+ print a number x number grid with each box of size width and height
+
+ :param number: number of grid boxes (row and column)
+
+ :param size: size of each grid box
+ """
+ # top row
+ top = ('+ ' + '- '*size)*number + '+' + '\n'
+ middle = ('| ' + ' '*2*size)*number + '|' + '\n'
+
+ row = top + middle*size
+
+ grid = row*number + top
+
+ print grid


def print_grid3(size):
"""
same as print_grid, but calling print_grid2 to do the work
"""
number = 2
box_size = (size-1) / 2 # size of one grid box
print_grid2(number, box_size)


print_grid(11)
print_grid(7)

print_grid2(3, 3)
print_grid2(3, 5)

print_grid3(11)
5 changes: 5 additions & 0 deletions Students/Lottsfeldt_Erik/Session01/sleep_in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def sleep_in(weekday, vacation):
if not weekday or vacation:
return True
else:
return False
8 changes: 8 additions & 0 deletions Students/Lottsfeldt_Erik/Session01/sum_double.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def sum_double(a, b):
# Store the sum in a local variable
sum = a + b

# Double it if a and b are the same
if a == b:
sum = sum * 2
return sum
9 changes: 9 additions & 0 deletions Students/Lottsfeldt_Erik/Session02/funky_bools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dist = sqrt( (x1-x2)**2 + (y1-y2)**2 )



x = 3
y = 2

print (dist)