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
16 changes: 16 additions & 0 deletions Students/apklock/session01/break_me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#NameError
def namey():
print those

#TypeError
def typey():
'a' - 'b'

#SyntaxError
def synt():
print 'synt

#AttributeError
def atty():
atty.attribute

12 changes: 12 additions & 0 deletions Students/apklock/session01/grid_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def grid():
print '+', '- - - -', '+', '- - - -', '+'
print '|', ' ', '|', ' ', '|'
print '|', ' ', '|', ' ', '|'
print '|', ' ', '|', ' ', '|'
print '|', ' ', '|', ' ', '|'
print '+', '- - - -', '+', '- - - -', '+'
print '|', ' ', '|', ' ', '|'
print '|', ' ', '|', ' ', '|'
print '|', ' ', '|', ' ', '|'
print '|', ' ', '|', ' ', '|'
print '+', '- - - -', '+', '- - - -', '+'
10 changes: 10 additions & 0 deletions Students/apklock/session01/grid_n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def grid_n(n): #n rows & columns
a = ' + ----'
b = ' | '
for i in range(n):
print a * n, '+'
print b * n, '|'
print b * n, '|'
print b * n, '|'
print b * n, '|'
print a * n, '+'
10 changes: 10 additions & 0 deletions Students/apklock/session01/grid_nx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def grid_nx(n,x): #n rows, x columns
a = ' + ----'
b = ' | '
for i in range(n):
print a * x, '+'
print b * x, '|'
print b * x, '|'
print b * x, '|'
print b * x, '|'
print a * x, '+'
12 changes: 12 additions & 0 deletions Students/apklock/session01/grid_three.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def grid_three(n): #n characters wide/tall
x = (n - 4) / 3
print '+', x * '-', '+', x * '-', '+', x * '-', '+'
for i in range(x):
print '|', x * ' ', '|', x * ' ', '|', x * ' ', '|'
print '+', x * '-', '+', x * '-', '+', x * '-', '+'
for i in range(x):
print '|', x * ' ', '|', x * ' ', '|', x * ' ', '|'
print '+', x * '-', '+', x * '-', '+', x * '-', '+'
for i in range(x):
print '|', x * ' ', '|', x * ' ', '|', x * ' ', '|'
print '+', x * '-', '+', x * '-', '+', x * '-', '+'
9 changes: 9 additions & 0 deletions Students/apklock/session01/print_grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def print_grid(n): #n characters wide/tall
x = (n - 3) / 2
print '+', x * '-', '+', x * '-', '+'
for i in range(x):
print '|', x * ' ', '|', x * ' ', '|'
print '+', x * '-', '+', x * '-', '+'
for i in range(x):
print '|', x * ' ', '|', x * ' ', '|'
print '+', x * '-', '+', x * '-', '+'
9 changes: 9 additions & 0 deletions Students/apklock/session02/ack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def ack(m,n): # m and n are integers in between 0 and 4
if m<0 or n<0:
return 'None'
elif m is 0:
return n+1
elif m>0 and n is 0:
return ack(m-1,1)
elif m>0 and n>0:
return ack(m-1, ack(m, n-1))
6 changes: 6 additions & 0 deletions Students/apklock/session02/dist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def dist(x1, y1, x2, y2):
x3 = abs(x1 - x2)
y3 = abs(y1 - y2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need the abs() ? you are going to square the value later...

z = (x3 * x3) + (y3 * y3)
return math.sqrt(z)

7 changes: 7 additions & 0 deletions Students/apklock/session02/lucas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def lucas(n): # return Lucas series to the 'nth' values
if n == 1:
return 2
elif n == 2:
return 1
else:
return lucas(n-2) + lucas(n-1)
5 changes: 5 additions & 0 deletions Students/apklock/session02/series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def series(n): # return Fibonacci series to the 'nth' value
if n < 2:
return n
return series(n-2) + series(n-1)

6 changes: 6 additions & 0 deletions Students/apklock/session02/sum_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def sum_series(l,m,n): # return the 'lth' place in the series with starting values of m and n

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to check for m,n < 0.

And you do want to put some test code in here with "assert" statements.

if l == 1:
return m
if l == 2:
return n
return sum_series(l-2,m,n) + sum_series(l-1,m,n)