Skip to content

Turning in week 2 assignments plus Python push ups from week 1 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions students/RobertKesterson/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Define the function
def first_last6(nums):
if nums[0] == 6 or nums[len(nums) - 1] == 6:
return True
else:
return False

# Call the function
first_last6(10, 8)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Define the function
def same_first_last(nums):
if len(nums) >= 1 and nums[0] == nums[len(nums) - 1]:
return True
else:
return False

# Call the function
same_first_last([10])
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Define the function
def cigar_party(cigars, is_weekend):
if not is_weekend and 40 <= cigars <= 60:
return True
if is_weekend and 40 <= cigars:
return True
else:
return False

# Call the function
cigar_party(35, False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Define the function
def date_fashion(you, date):
if you >= 8 and date >= 3:
return 2
elif you >= 3 and date >= 8:
return 2
elif you <= 2 or date <= 2:
return 0
else:
return 1

# Call the function
date_fashion(2, 9)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Define the function
def hello_name(name):
greetingString = "Hello " + name + "!"
return greetingString

# Call the function
hello_name('Alice')
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Define the function
def make_abba(a, b):
abba_string = a + b + b + a
return abba_string

# Call the function
make_abba('hello','Captain')
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Define the function
def monkey_trouble(a_smile, b_smile):
if a_smile and b_smile:
return True
elif not a_smile and not b_smile:
return True
else:
return False

# Call the function
monkey_trouble(True, True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Define the function
def sleep_in(weekday, vacation):
if vacation or weekday is False:
return True
else:
return False

# Call the function
sleep_in(False, True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -------------------------------------------- #
# Title: Lesson 02 Exercise: Fibonacci Series
# Desc: Holds functions (and asset tests) related to the Fibonacci and Lucas series
# Change log: (who, when, what)
# RKesterson, 2019-01-22, Created file
# RKestesron, 2019-01-22, Stubbed out methods / parts
# RKesterson, 2019-01-22, Completed step one (fibonacci function)
# RKesterson, 2019-01-22, Completed step two (lucas function)
# RKesterson, 2019-01-22, Completed step three (sum_series function)
# RKesterson, 2019-01-22, Completed testing using assert statements
# ---------------------------------------------- #

# Define the function
def fibonacci(n):
""" compute the nth Fibonacci number """
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n - 2) + fibonacci(n - 1)
pass

# Call the function
#print(fibonacci(7))

# Define the function
def lucas(n):
""" compute the nth Lucas number """
if n == 0:
return 2
elif n == 1:
return 1
else:
return lucas(n - 2) + lucas(n - 1)
pass

# Call the function
#print(lucas(5))

# Define the function
def sum_series(n, m = 0, o = 1):
"""
compute the nth value of a summation series.

:param n0=0: value of zeroth element in the series
:param n1=1: value of first element in the series

This function should generalize the fibonacci() and the lucas(),
so that this function works for any first two numbers for a sum series.
Once generalized that way, sum_series(n, 0, 1) should be equivalent to fibonacci(n).
And sum_series(n, 2, 1) should be equivalent to lucas(n).
"""
if n == 0:
return m
elif n == 1:
return o
else:
return sum_series(n - 2, m, o) + sum_series(n - 1, m, o)
pass

# Call the function
#print(sum_series(4, 2, 1))

if __name__ == "__main__":
# run some tests
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
assert fibonacci(6) == 8
assert fibonacci(7) == 13

assert lucas(0) == 2
assert lucas(1) == 1

assert lucas(4) == 7

assert sum_series(5) == fibonacci(5)

# test if sum_series matched lucas
assert sum_series(5, 2, 1) == lucas(5)

print("tests passed")
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -------------------------------------------- #
# Title: Lesson 02 Exercise: Fizz Buzz
# Desc: The classic fizz buzz interview question, spoken of in song and story
# Change log: (who, when, what)
# RKesterson, 2019-01-22, Created file
# RKestesron, 2019-01-22, Stubbed out methods / parts
# RKesterson, 2019-01-22, Completed program
# ---------------------------------------------- #

# Define the function
def fizzBuzz():
i = 1
while i < 101:
if (i % 3 == 0 and i % 5 == 0):
print('FizzBuzz')
elif (i % 3 == 0 and i % 5 != 0):
print('Fizz')
elif (i % 3 != 0 and i % 5 == 0):
print('Buzz')
else:
print(i)
i += 1

# Call the function
fizzBuzz()
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -------------------------------------------- #
# Title: Lesson 02 Exercise: Grid Printer
# Desc: Prints out grids of different sizes using different functions
# Change log: (who, when, what)
# RKesterson, 2019-01-22, Created file
# RKestesron, 2019-01-22, Stubbed out methods / parts
# RKesterson, 2019-01-22, Completed part one
# RKesterson, 2019-01-22, Completed part two
# RKesterson, 2019-01-22, Completed part three
# ---------------------------------------------- #

# Part one
levelOne = '+ - - - - + - - - - +'
levelTwo = '| | |'

print(levelOne)
print(levelTwo)
print(levelTwo)
print(levelTwo)
print(levelTwo)
print(levelOne)
print(levelTwo)
print(levelTwo)
print(levelTwo)
print(levelTwo)
print(levelOne)

# Part two
# Define the function
def print_grid(n):
dashCount = int(n / 2)
post = '+ '
column = '| '
floor = '- '
openFloor = ' '
levelOne = post + floor * dashCount + post + floor * dashCount + post
levelTwo = column + openFloor * dashCount + column + openFloor * dashCount + column
print(levelOne)
i = 0
while i < dashCount:
print(levelTwo)
i += 1
print(levelOne)
i = 0
while i < dashCount:
print(levelTwo)
i += 1
print(levelOne)

# Call the function
print_grid(15)

# Part three
# Define the function
def print_grid2(n, m):
unitTop = '+ ' + '- ' * m
unitTopFull = unitTop * n + '+'
unitBottom = '| ' + ' ' * m
unitBottomFull = unitBottom * n + '|'
i = 0
while i < n:
print(unitTopFull)
j = 0
while j < m:
print(unitBottomFull)
j += 1
i += 1
print(unitTopFull)

# Call the function
print_grid2(5, 3)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Define the function
def big_diff(nums):
largestObserved = nums[0]
smallestObserved = nums[0]
iCounter = 1
while iCounter < len(nums):
smallestObserved = min(smallestObserved, nums[iCounter])
largestObserved = max(largestObserved, nums[iCounter])
iCounter += 1
difference = largestObserved - smallestObserved
return difference

# Call the function
big_diff([10, 2])
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Define the function
def count_evens(nums):
evenCount = 0
indexI = 0
while indexI < len(nums):
if nums[indexI] % 2 == 0:
evenCount += 1
indexI += 1
return evenCount

# Call the function
count_evens([2, 7, 1, 4])
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Define the function
def lone_sum(a, b, c):
sum = 0
if a != b and a != c and b !=c:
sum = a + b + c
elif a != b and b == c:
sum = a
elif a == b and b != c:
sum = c
elif a == c and b != c:
sum = b
return sum

# Call the function
lone_sum(2, 3, 5)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Define function
def lucky_sum(a, b, c):
sum = 0
if a == 13:
sum = 0
elif b == 13:
sum = a
elif c == 13:
sum = a + b
else:
sum = a + b + c
return sum

# Call function
lucky_sum(2, 3, 5)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Define the function
def count_hi(str):
count = 0
iCounter = 0
while (iCounter < len(str)):
if str[iCounter:iCounter + 2] == 'hi':
count += 1
iCounter += 1
return count

# Call the function
count_hi('hihellofromMadagascarhi')
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Define the function
def double_char(str):
result = ''
for i in range(len(str)):
result = result + str[i] * 2
return result

# Call the function
double_char('cow-a-bunga')
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Define the function
def front_times(str, n):
return str[0:3] * n

# Call the function
front_times('ello', 4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ddefine the function
def string_times(str, n):
return str * n

# Call the function
string_times('argghh says Charlie Brown', 3)
1 change: 1 addition & 0 deletions students/RobertKesterson/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the base readme to create the new txt file that is needed.