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
26 changes: 26 additions & 0 deletions Students/Tyler G/session2/Ack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys

def Ack(m, n):
"""
This is the Ackerman function
which is recursive and I don't understand
all that well. It returns a non-negative integer.
"""
if m < 0 or n < 0:
return None
if m == 0:
return n + 1
elif m > 0 and n == 0:
return Ack(m-1,1)
elif m > 0 and n > 0:
return Ack(m-1,Ack(m,n-1))

def main():
m_entry = int((sys.argv[1]))
n_entry = int((sys.argv[2]))

print Ack(m_entry, n_entry)

if __name__ == "__main__":
main()

23 changes: 23 additions & 0 deletions Students/Tyler G/session2/Session2_ExtraCredit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


#Session 2 Extra Credit
def FizzBuzzFrodoBilboGandalf(n):
for i in range(1,n+1):
holder = " "
if i % 3 == 0:
holder += "Fizz"
if i % 5 == 0:
holder += "Buzz"
if i % 7 == 0:
holder += "Frodo"
if i % 11 == 0:
holder += "Bilbo"
if i % 13 == 0:
holder += "Gandalf"
if holder == " ":
print i
else:
print holder.lstrip(" ")


FizzBuzzFrodoBilboGandalf(100)
40 changes: 40 additions & 0 deletions Students/Tyler G/session2/series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
def fibonacci(n):
"""
Returns the nth value of the fibonacci sequence.
"""
sequence = [0,1]
for i in range(n-2):
sequence.append(sequence[len(sequence)-2] + sequence[len(sequence)-1])
return sequence[n-1]

def lucas(n):
"""
Returns the nth value of the lucas sequence. It is
the same as the fibonacci series except the starting
numbers are 2 and 1 instead of 0 and 1.
"""
sequence = [2,1]
for i in range(n-2):
sequence.append(sequence[len(sequence)-2] + sequence[len(sequence)-1])
return sequence[n-1]

def sum_series(n, o = 0, p = 1):
"""
First parameter returns nth value of series. The second
and third optional parameters allows the user to define
the first two values in the fibonacci sequence.
"""
sequence = [o, p]
for i in range(n-2):
sequence.append(sequence[len(sequence)-2] + sequence[len(sequence)-1])
return sequence[n-1]

def main():
n_entry = int((sys.argv[1]))
o_entry = int((sys.argv[2]))
p_entry = int((sys.argv[3]))

print sum_series(n_entry, o_entry, p_entry)

if __name__ == "__main__":
main()
85 changes: 85 additions & 0 deletions Students/Tyler G/session3/list_lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
fruits = ["Apples", "Pears", "Oranges", "Peaches"]

for fruit in fruits:
print fruit

new_fruit = raw_input("What kind of fruit would you like you to add to the list? ")
fruits.append(new_fruit)

for fruit in fruits:
print fruit

number = raw_input("Enter a whole number: ")
try:
number = int(number)
except ValueError:
print "Must be a whole number!"

x = 0
for i in range(number,number + len(fruits)):
print "%i is to %s." % (number, fruits[x])
number += 1
x += 1

fruits.insert(0,"Bananas")

print "Only fruits which start with 'p':"
for fruit in fruits:
if fruit[0].lower() == "p":
print fruit

print "Full list:"
for fruit in fruits:
print fruit

fruits.pop(0)

print "First element removed:"
for fruit in fruits:
print fruit

removed_fruit = str(raw_input("Type the name of the fruit you wish to remove from the list: "))

list_size = len(fruits)
for fruit in fruits:
if removed_fruit.lower() == fruit.lower():
fruits.remove(fruit)
if list_size == len(fruits):
print "Could not find '%s' in the list of fruits!" % removed_fruit

print "Full list:"
for fruit in fruits:
print fruit


for fruit in fruits:
print "Do you like %s?" % fruit
removed_fruits = []
while True:
question = raw_input("Enter 'yes' or 'no': ")
if question.lower() == "no":
print "Removing %s.." % fruit
removed_fruits.append(fruit)
break
elif question.lower() == "yes":
print "Keeping %s.." % fruits
break
else:
print "You must enter 'yes' or 'no'!"
for fruit in fruits:
if fruit in removed_fruits:
fruits.remove(fruit)


print "Here's the list of fruits again: "
for fruit in fruits:
print fruit

new_fruits = []

for i in fruits:
new_fruits.append(i[::-1])

print "Now here's the fruit list with each element reversed: "
for i in new_fruits:
print i
93 changes: 93 additions & 0 deletions Students/Tyler G/session3/mailroom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from textwrap import dedent
import math

# Original list of historical donors and their amounts donated
donations = []
donations.append( ("Marshawn Lynch", [238.99, 159.23]) )
donations.append( ("Russell Wilson", [9910.00, 159.23, 357.00]) )
donations.append( ("Richard Sherman", [426.48, 3859.94, 5496.00]) )
donations.append( ("Kam Chancellor", [999.99]) )
donations.append( ("Bobby Wagner", [999.99]) )

def show_donations():
x = 0
print "\nThe names of previous donors are: "
for person in donations:
print donations[x][0]
x += 1

def write_thank_you(name, amount):
print dedent('''
Dear %s,
Thank you for your very kind donation of $%d.
It will be put to very good use.
Sincerely,
-The Team
''') % (name, amount)

def check_add_donators(name):
x = 0
move_on = False
for person in donations:
if name.lower() == donations[x][0].lower():
print "\n%s is a previous donor!" % donations[x][0]
choice = None
while not choice:
amount = raw_input("Please add another donation entry for this individual. Be sure to enter an integer or float: ")
try:
choice = float(amount)
except ValueError:
print "Must be an integer or float value!"
donations[x][1].append(float(amount))
write_thank_you(donations[x][0], float(amount))
move_on = True
x += 1
if move_on == False:
print "\n%s is a new donor! Adding the name to registry." % name
choice = None
while not choice:
amount = raw_input("How much $ did this individual donate? Be sure to enter an integer or float: ")
try:
choice = float(amount)
except ValueError:
print "Must be an integer or float value!"
donations.append( (name, [float(amount)]) )
write_thank_you(name, float(amount))

def sort_key(item):
return item[1]

def create_report():
report = []
for (name, amount) in donations:
total = sum(amount)
count = len(amount)
avg = total / count
report.append( (name, total, count, avg) )
report.sort(key=sort_key)
print "%25s | %11s | %9s | %12s" % ("Name", "Total Donated", "Freq Donated", "Avg Donated")
print "-"*66
x = 0
for row in report:
print "%25s %11.2f %12i %17.2f" % row

print "\n"
print "*"*10, "Welcome to the Mailroom command-line script", "*"*10
while True:
print dedent('''
Type "list" to show the names of our donors. Type "Thank You" to generate
a thank-you letter to a donor. Type "Create Report" to generate a report
of our donors which includes their number of donations, average donation,
and total donation amounts. Finally, type "Exit" to exit the program.''')
response = raw_input("\nWhich option you like to select?: ")
if response.lower() == "list":
show_donations()
if response.lower() == "thank you":
name_query = raw_input("Enter the full name of the donor: ")
check_add_donators(name_query)
if response.lower() == "create report":
create_report()
if response.lower() == "exit":
print "Exiting now..."
break

30 changes: 30 additions & 0 deletions Students/Tyler G/session3/rot13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Returns a dictionary of the alphabet encrypted. The shift value is 13 by default.
def code_shift(shift = None):
if shift == None:
shift = 13
letters = "abcdefghijklmnopqrstuvwxyz"
coder = {}
x = 0
for i in range(len(letters)):
if i < (len(letters)-shift):
coder[letters[i]] = letters[i + shift]
else:
coder[letters[i]] = letters[x]
x += 1
return coder

def rot13(n):
encrypted = code_shift()
holder = " "
for char in n:
if char.lower() in encrypted:
if char == char.lower():
holder += encrypted[char.lower()]
else:
holder += encrypted[char.lower()].upper()
else:
holder += char
return holder.lstrip(" ")



40 changes: 40 additions & 0 deletions Students/Tyler G/session3/string_lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Slicing lab
def switch(n):
return n[-1:] + n[1:-1] + n[:1]

def every_other[n]
return n[::2]

def big_string(n):
return every_other(n[4:-4])

def big_strip2(n):
return n[4:-4:2]

def reverse_sequence(n):
return n[::-1]

def third_chop(n):
thirds = len(n) / 3
first_third = n[:thirds]
middle_third = n[thirds:2*thirds]
last_third = n[2*thirds:]
return middle_third + last_third + first_third



# Session 3 Extra Credit
def FizzBuzzAll(n, dictionary = None):
if dictionary == None:
dictionary = {3: "Fizz", 5: "Buzz", 7: "Frodo", 11: "Bilbo", 13: "Gandalf"}
assert type(n) == int and type(dictionary) == dict, "You must insert an integer and an optional dictionary."
for num in range(1, n + 1):
holder = " "
for value in dictionary:
if num % value == 0:
holder += dictionary[value]
if holder != " ":
print holder.lstrip(" ")
else:
print num