Skip to content

Justin jameson #8

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 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def diff21(n):
if n > 21:
return (abs (n-21)*2)
else:
return abs (n-21)

def parrot_trouble(talking, hour):
return (talking and (hour <7 or hour >20))

def makes10(a, b):
return (a+b==10 or a ==10 or b==10)

def near_hundred(n):
return ((n <=110 and n >=90) or (n<=210 and n >=190))

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))
10 changes: 10 additions & 0 deletions students/Justin Jameson/JustinJameson-A01/Sleep_In.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def sleep_in(weekday, vacation):

# sleep in if week day is false or or vacation is true

if not weekday or vacation:

return True

else: return False

29 changes: 29 additions & 0 deletions students/Justin Jameson/JustinJameson-A01/break_me_JJameson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#####################################
#TITLE: Lab 1-1
#Change Log: (Who, When, What)
#JJameson, 01 12 2019: created File
####################################

#Defining functions
def causeNameErrorException ():
#raise NameError("Error") the name error will raise an exception because the name 'nameNotFound' does not exist.
print(nameNotFound)


def causeTypeError ():
#raise TypeError() the type error will raise an exception because I am mixing intigers and strings.
print ('yes' + 6)

def causeSyntaxError():
# raise SyntaxError() the syntax error will raise an exception because I did not include parenthesis in my print\
# statement.
#print "I forgot the parenthesis"

def caauseAttributeError():# raise AttributeError() the attribute error will raise an exception because I did not define the attribuete 'broken' print.broken


# Calling the functions.
#causeNameErrorException()
#causeTypeError()
#causeSyntaxError()
causeAttributeError()
1 change: 1 addition & 0 deletions students/Justin Jameson/JustinJameson-A01/newtext.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is AWESOME!!!!
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# **************************
# Title: Grid Maker
# Desc: creates a grid based on user input.
# Change Log:
# Justin Jameson, 01/17/2019, version 1
# **************************


# -- Data --#
# declare variables and constants
intCounter = 0
# intCounter is used in the while loop to create the rows.
# rowWidth = the graphics formula for printing the top and bottom row of the grid.
# rowHeight = the graphics formula for printing the sides of the grid.
# gx is user input that defines the width of the cells.
# gy is user input that defines the height of the cells.
# nColumns is user input that defines how many Columns to print.
# nRows is user input that defines how many rows to print.

# -- Processing -- #


def GridGraphics(gx, gy, nColumns):
"""
:param gx: defines width of the row
:param gy: defines height of the row
:param nColumns: defines the number of Columns
:return: returns gx-1 dashes and gy-2
"""
rowWidth = ("+"+(gx * " - ")+"+")+(((gx * " - ")+"+")* (nColumns - 1))
rowHeight = (("|"+(gx*" ") + "|") + (((gx*" ") + "|")* (nColumns - 1)) + "\n")* gy
return rowWidth, rowHeight
# end function GridGraphics


# -- Presentation (Input/Output) --#

# get user input
# user defines height and width of the cell(s).
print("First, lets define the cell size. ")
cellWidth = int(input("Enter the width of the cell: "))
cellHeight = int(input("Enter the height of the cell: "))
print("Now lets define the grid. ")
numberColumns = int(input("Enter the number of columns: "))
nRows = int(input("Enter the number of row: "))

# Send program output, printing out the grids.
while intCounter < nRows:
rW, rH = GridGraphics(cellWidth, cellHeight, numberColumns)
print(rW + "\n" + rH, end="")
intCounter = intCounter + 1
# End of while loop
# Print out the final set of + -
print(rW)



Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# **************************
# Title: Justin Jameson 2_2 Fizz Buzz
# Desc: Fizz Buzz assignment
# Change Log: (Who, When, What)
# Justin Jameson, 01162019, created template
# Justin Jameson, 01182019, worked on turning into a function, but could'nt figure out how to print each iteration of i.
# Justin Jameson, 01212019, reverted a little bit, now printing from the function.
#
# **************************


# -- Data --#
# declare variables and constants
# -- Processing --#
# perform tasks
# Function to return process the range and if then statements.
def RangeAndVar(range1=0, range2 = 100, intReplaceN1=3, intReplaceN2=5, buzzWord1="Fizz", buzzWord2="Buzz"):
for i in range(range1, range2):
if i % intReplaceN1 and i % intReplaceN2 == 0:
print(buzzWord1, buzzWord2)
elif i % intReplaceN1 == 0:
print(buzzWord1)
elif i % intReplaceN2 == 0:
print(buzzWord2)
else: print(i)
# end of function RangeAndVar

# -- Presentation (Input/Output) --#
# get user input


range1 = int(input("Enter the first number of the range: "))
range2 = int(input("Enter the last number of the range: "))
intReplaceN1 = int(input("Enter the first multiple you would like to replace: "))
intReplaceN2 = int(input("Enter the second multiple you would like to replace: "))
buzzWord1 = input("Enter the first 'buzz word' to replace the first multiple: ")
buzzWord2 = input("Enter the second 'buzz word' to replace the second multiple: ")

RangeAndVar(range1, range2, intReplaceN1, intReplaceN2,buzzWord1,buzzWord2)




Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# under standing slicing

x = "got new shoes"
print(x) # got new shoes
print(x[0:3]) got
print(x[:3]) got
print(x[3:]) new shoes
print(x) got new shoes

# Given a string, return a new string where "not " has been added to the front.
# However, if the string already begins with "not", return the string unchanged.

def not_string(str):
# check to see if not exists in front of the string
if str [:3] == 'not':
return str
# concatinate the strings together.
return "not " + str

# Given a non-empty string and an int n, return a new string where the char at index n has
# been removed. The value of n will be a valid index of a char in the original string

def missing_char(str, n):
return str[:n] + str[n+1:]

# Given a string, return a new string where the first and last chars have been exchanged.
# my solution was incorrect.

def front_back(str):
firstLetter = str[:1]
lastLetterPosition = int(len(str))
inbeween = str[1:(lastLetterPosition - 1)]
lastLetter = str[lastLetterPosition - 1:]
return lastLetter+inbeween+firstLetter

# correct answer:
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]


# Given a string, we'll say that the front is the first 3 chars of the string. If the string
# length is less than 3, the front is whatever is there. Return a new string which is 3
# copies of the front.

def front3(str):
front = str[:3]
return front*3
96 changes: 96 additions & 0 deletions students/Justin Jameson/JustinJameson-A02/Justin Jameson Series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#**************************
#Title: Series.py
#Desc: Computing the Fibonacci, Lucas Series, and sum_series.
#Chnage Log: (Who, When, What)
# Justin Jameson, 01212019, created 3 functions, output answers, and checked with assertions.
#**************************


#-- Data --#
# declare variables and constants
#-- Processing --#
# perform tasks

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


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


def sum_series(n, n0=0, n1=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 n0
elif n == 1:
return n1
else:
return sum_series(n - 1, n0, n1) + sum_series(n - 2, n0, n1)




#-- Presentation (Input/Output) --#
# get user input


n = int(input("For numbers 0 to n, enter the nth number you woul like calculated: "))
n0 = int(input("Enter the value of zeroth element in the series, n0: "))
n1 = int(input("Enter the value of first element in the series, n1: "))
print(fibonacci(n))
print(lucas(n))
print(sum_series(n,n0,n1))


# send program output


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(2) == 3
assert lucas(3) == 4
assert lucas(4) == 7
assert lucas(5) == 11



assert sum_series(5) == fibonacci(5)

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

print("tests passed")