Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
da8abf4
new file: Solutions/session_01/box_builder.py
Anastomose Oct 7, 2014
89f335a
Merge remote-tracking branch 'upstream/master'
Anastomose Oct 11, 2014
d4c79af
Updated ack.py with docstring
Anastomose Oct 12, 2014
2552010
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroToP…
Anastomose Oct 12, 2014
c545eb7
Updated ack.py with docstring
Anastomose Oct 12, 2014
fa121d3
Created draft fibbo function
Anastomose Oct 12, 2014
208a386
Expanded fibbo function
Anastomose Oct 13, 2014
4d2fce3
Simplified fibo function.
Anastomose Oct 14, 2014
f8afc08
Added sum_series function to series.py module.
Oct 14, 2014
1ee021f
Added test block to series.py for main assert
Anastomose Oct 14, 2014
26046a2
Created my own working dir
Anastomose Oct 14, 2014
072d7e3
Finally saw the reply and got everything in the right spot
Anastomose Oct 14, 2014
a0e1b48
RM working dir
Anastomose Oct 14, 2014
4d43ce2
Dropped readme in s3 working dir
Anastomose Oct 14, 2014
8901346
Fixed an error in fizzbuzz.py
Anastomose Oct 15, 2014
683bf49
Merge branch 'master' into session3
Anastomose Oct 15, 2014
25147be
Adding list lab, string functions, and class notes.
Oct 15, 2014
9054b2b
Updated string funcs, list lab.
Anastomose Oct 15, 2014
c51a7e5
Updated list_lab.py with part 2
Anastomose Oct 15, 2014
a000970
Dropped readme, list_lab.py changes
Oct 15, 2014
f774dd8
Trying to get list lab back in the correct dir
Oct 15, 2014
c8e216d
list_lab.py reinstated as file in correct dir
Oct 15, 2014
ab4c99d
Finished part 4 of the list lab
Oct 15, 2014
1168e5e
Added string printing lab, updated notes
Oct 16, 2014
43bef15
rot13 using translate method
Oct 16, 2014
0859d1d
Started mailroom.py
Oct 16, 2014
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
28 changes: 28 additions & 0 deletions Students/ebuer/session_01/box_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
##gridprinter python script
##written by EB 2014-10-04


def print_grid():
separator = 2 * ('+' + 4 * ' -' + ' ') + '+' + '\n'
walls = 2 * (('|' + 4 * ' ') + ' ') + '|' + '\n'

print 2 * (separator + 4 * walls) + separator

print_grid()


def scale_grid(n):
separator = 2 * ('+' + n * ' -' + ' ') + '+' + '\n'
walls = n * (2 * (('|' + n * ' ') + ' ') + '|' + '\n')
print 2 * (separator + walls) + separator

scale_grid(9)


def expand_grid(num_rows, scale_factor):
separator = num_rows * ('+' + scale_factor * ' -' + ' ') + '+' + '\n'
walls = scale_factor * (num_rows * (('|' + scale_factor * ' ')
+ ' ') + '|' + '\n')
print (num_rows * (separator + walls) + separator)

expand_grid(3, 4)
17 changes: 17 additions & 0 deletions Students/ebuer/session_01/break_me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#create four functions that raise errors

##NameError Function
def bad_name(str):
return a_bad_name

##TypeError function -- enter a string to receive TypeError
def a_bad_type(string_val):
return string_val + 5

##SyntaxError function -- any value will do
def a_syn_error(some_value):
n +,= 1

##AttributeError function -- enter an integer
def att_error(n):
n.title()
10 changes: 10 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/diff_21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def diff21(n):
if n >= 21:
return 2 * (n - 21)
else:
return 21 - n

n = 21
ans = diff21(n)

print ans
29 changes: 29 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/front_back.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
##make a function that swaps first and last letter of a string


def front_back(str):
if len(str) > 1:
first_letter = str[0]
last_letter = str[len(str) - 1]
mid_letters = str[1:len(str) - 1]
return last_letter + mid_letters + first_letter
else:
return str

#codingbat solution
# def front_back(str):
# if len(str) <= 1:
# return str

# mid = str[1:len(str)-1] # can be written as str[1:-1]

# # last + mid + first
# return str[len(str)-1] + mid + str[0]


def front3(str):
if len(str) <= 3:
return 3 * str
return 3 * str[0:3]

#codingbat says slicing is silent on indexing errors, not sure aobut this
24 changes: 24 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/monkey_trouble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

def monkey_trouble(a_smile, b_smile):
if (a_smile and b_smile) or (not a_smile and not b_smile):
return True
else:
return False

a_smile = False
b_smile = True

answer_1 = monkey_trouble(a_smile, b_smile)
print answer_1, a_smile, b_smile

"""
solution notes really short answer:
def more_trouble(a_smile, b_smile)
return (a_smile==b_smile)
"""

def more_trouble(a_smile, b_smile):
return (a_smile==b_smile)
answer_2=more_trouble(a_smile, b_smile)
print answer_2

35 changes: 35 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/near_hundred.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
##given an integer n return true when it is within 10 of 100 or 200


def near_hundred(i):
temp1 = abs(100 - i)
temp2 = abs(200 - i)
if temp1 < 10 or temp2 < 10:
return True

i = 91
print 'Near Hundred Result:', near_hundred(i)


##pos_neg()

def pos_neg(a, b, negative):
if {(a > 0 and b < 0) or (a < 0 and b > 0)} and not negative:
return True
elif (a < 0 and b < 0) and negative:
return True
else:
return False

a = -3
b = -2
negative = True

print 'Positive Negative Result:', pos_neg(a, b, negative)

#codingbat solution
# def pos_neg(a, b, negative):
# if negative:
# return (a < 0 and b < 0)
# else:
# return ((a < 0 and b > 0) or (a > 0 and b < 0))
25 changes: 25 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/not_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#the not string function


def not_string(str):
if str.find('not') > 0 or str.find('not') == -1:
return 'not ' + str
else:
return str

str = 'not candy bad'
print 'Not string result:', not_string(str)

print str.find('not')

##codingbat solution, note use of double returns since only 1 is executed
# def not_string(str):
# if len(str) >= 3 and str[:3] == "not":
# return str
# return "not " + str
# # str[:3] goes from the start of the string up to but not
# # including index 3


def missing_char(str, n):
return str[:n - 1] + str[n:]
36 changes: 36 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/parrot_trouble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
##parrot trouble in paradise


def parrot_trouble(talking, hour):
if not talking:
return False
elif hour < 7 or hour > 20:
return True
else:
return False

talking = True
hour = 8

print parrot_trouble(talking, hour)

"""
def parrot_trouble(talking, hour):
return (talking and (hour < 7 or hour > 20))
# Need extra parenthesis around the or clause
# since and binds more tightly than or.
# and is like arithmetic *, or is like arithmetic +
"""

#makes 10

def makes10(a, b):
if a == 10 or b == 10:
return True
elif a + b == 10:
return True
else:
return False
a = 5
b = 10
print 'Makes 10:', makes10(a, b)
21 changes: 21 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/sleep_in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Written by EB, 2014-10-01
create a function that takes two variables and runs logical eval

sleep in when it is not a weekday, or you are on vacation
do not sleep in on a weekday that is not vacation
"""


def sleep_in(weekday, vacation):
if not weekday or vacation:
return True
else:
return False

weekday = False
vacation = True

result = sleep_in(weekday, vacation)

print result
48 changes: 48 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/string_times.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

def string_times(str, n):
return n * str

def front_times(str, n):
front_end=str[:3]
return n * front_end

def string_bits(str):
copier = True
print_string = ''
for l in str:
if copier:
print_string += l
print print_string
copier = False
else:
copier = True
return print_string

str=''
print string_bits(str)

def string_splosion(str):
print_string=''
for n in range(len(str)):
temp = str[0:n+1]
#print_string += temp
print print_string
return print_string

str='Code'
string_splosion(str)

def last2(str):
end_string = str[-2:]
i = 0
for n in range(len(str)-2):
if str[n:n+2] == end_string:
i += 1
return i

def count9(nums):
i = 0
for n in nums:
if n == 9:
i += 1
return i
15 changes: 15 additions & 0 deletions Students/ebuer/session_01/codebat_solutions/sum_double.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##sum_double excercise
##given two int values return sum unless the two are == then double sum


def sum_double(x, y):
if x == y:
return 2 * (x + y)
else:
return x + y

x = 3
y = 3
z = sum_double(x, y)

print "Solution: %i"% z
35 changes: 35 additions & 0 deletions Students/ebuer/session_02/ack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def ack(m, n):
"""Perfom Ackermann function calculation.

Syntax: ack(m, n)

Arguments:
m -- a positive integer
n -- a positive integer
Function will return "none" if a negative argument is passed.

When run in __main__ namespace function will test several
primary inputs to ensture correct function. Passage of all
tests will generate a pass message.

Note: the Ackermann function is very computationally intensive
and will flood most desktop computers' available RAM for (m, n)
greater than (3, 4).
"""
if m < 0 or n < 0:
return None
elif not m:
return n + 1
elif not n:
return ack(m - 1, 1)
else:
return ack(m - 1, ack(m, n - 1))

if __name__ == "__main__":
assert ack(0, 0) == 1
assert ack(1, 0) == 2
assert ack(2, 0) == 3
assert ack(3, 0) == 5
assert ack(4, 0) == 13
assert ack(3, 4) == 125
print "\nAll tests pass.\nCongratulations, you've done it again Mr. Wayne."
Binary file added Students/ebuer/session_02/ack.pyc
Binary file not shown.
17 changes: 17 additions & 0 deletions Students/ebuer/session_02/fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

def fizzbuzz(rng):
for r in rng:
if not r % 3 and not r % 5:
print "fizzbuzz"
elif not r % 3:
print "fizz"
elif not r % 5:
print "buzz"
else:
print r

GLOBAL_RANGE = range(100)

fizzbuzz(GLOBAL_RANGE)

print locals()
Loading