Skip to content

Adding in Lesson1 assignments under /students/visokoo #3

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 14 commits into
base: master
Choose a base branch
from
25 changes: 25 additions & 0 deletions students/visokoo/00-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### About Me

#### Intro
I started out in the tech world as a Helpdesk Specialist and was given
the opportunity move into the DevOps space about 2 years ago. It was a
rollercoaster ride going from full Windows to Linux but I loved every
moment of it.

I've done some basic coding with ruby for some day to day tasks but I'm
really hoping to be able to do more with python like writing full-fledged
web apps or just something better than your standard script.

In my freetime I generally enjoy:

- Playing boardgames...
- Playing console/PC games...
- Thinking about solutions for work...
- Eating too much...
- Outdoor activities such as hiking, snowboarding, etc.

### Goal

I've done some basic coding with ruby for some day to day tasks but I'm
really hoping to be able to do more with python like writing full-fledged
web apps/cli tools or just something better than your standard script.
29 changes: 29 additions & 0 deletions students/visokoo/lesson1_assignments/break_me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'''
----------------------------------------------------
Assignment: Explore Errors
Author: visokoo | Created: 1/13/2019
ChangeLog: 1/13/2019, Created file
Create a script with four exceptions
----------------------------------------------------
'''

def name_error(x):
print(y)

#name_error(x)

def value_error(x):
int(x)
print(x, "blah")

#value_error("duh")

def zero_division(x):
return x / 0

#zero_division(2)

#def syntax_error(x)
# print(x)
21 changes: 21 additions & 0 deletions students/visokoo/lesson1_assignments/diff21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 1 - diff21.py
Author: visokoo | Created: 1/9/2019
ChangeLog: 1/9/2019, Created file
Given an int n, return the absolute difference between n and 21,
except return double the absolute difference if n is over 21.
diff21(19) → 2
diff21(10) → 11
diff21(21) → 0
----------------------------------------------------
'''

def diff21(n):
if n > 21:
return abs(21-n)*2
else:
return abs(21-n)
22 changes: 22 additions & 0 deletions students/visokoo/lesson1_assignments/makes10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 1 - makes10.py
Author: visokoo | Created: 1/9/2019
ChangeLog: 1/9/2019, Created file
Given 2 ints, a and b, return True if one if them is 10 or if their sum is 10.
makes10(9, 10) → True
makes10(9, 9) → False
makes10(1, 9) → True
----------------------------------------------------
'''

def makes10(a,b):
if a == 10 or b == 10:
return True
elif a + b == 10:
return True
else:
return False
18 changes: 18 additions & 0 deletions students/visokoo/lesson1_assignments/near_hundred.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 1 - near_hundred.py
Author: visokoo | Created: 1/9/2019
ChangeLog: 1/9/2019, Created file
Given an int n, return True if it is within 10 of 100 or 200.
Note: abs(num) computes the absolute value of a number.
near_hundred(93) → True
near_hundred(90) → True
near_hundred(89) → False
----------------------------------------------------
'''

def near_hundred(n):
return abs(100 - n) <= 10 or abs(200-n) <= 10
23 changes: 23 additions & 0 deletions students/visokoo/lesson1_assignments/parrot_trouble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 1 - parrot_trouble.py
Author: visokoo | Created: 1/9/2019
ChangeLog: 1/9/2019, Created file
We have a loud talking parrot. The "hour" parameter is the current
hour time in the range 0..23. We are in trouble if the parrot is
talking and the hour is before 7 or after 20. Return True if we are
in trouble.
parrot_trouble(True, 6) → True
parrot_trouble(True, 7) → False
parrot_trouble(False, 6) → False
----------------------------------------------------
'''

def parrot_trouble(talking, hour):
if talking == True and (hour < 7 or hour > 20):
return True
else:
return False
24 changes: 24 additions & 0 deletions students/visokoo/lesson1_assignments/pos_neg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 1 - pos_neg.py
Author: visokoo | Created: 1/9/2019
ChangeLog: 1/9/2019, Created file
Given 2 int values, return True if one is negative and one is
positive. Except if the parameter "negative" is True, then
return True only if both are negative.
pos_neg(1, -1, False) → True
pos_neg(-1, 1, False) → True
pos_neg(-4, -5, True) → True
----------------------------------------------------
'''

def pos_neg(a, b, negative):
if negative == True:
return (a < 0 and b < 0)
else:
return (a < 0 and b > 0) or (a > 0 and b < 0)

23 changes: 23 additions & 0 deletions students/visokoo/lesson1_assignments/sum_double.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 1 - sum_double.py
Author: visokoo | Created: 1/9/2019
ChangeLog: 1/9/2019, Created file
Given two int values, return their sum. Unless the two values
are the same, then return double their sum.
sum_double(1, 2) → 3
sum_double(3, 2) → 5
sum_double(2, 2) → 8
----------------------------------------------------
'''

def sum_double(a, b):
if a == b:
return ((a + b) * 2)
else:
return a + b
24 changes: 24 additions & 0 deletions students/visokoo/lesson2_assignments/fizz_buzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''
----------------------------------------------------
Assignment: fizz_buzz.py
Author: visokoo | Created: 1/20/2019
ChangeLog: 1/20/2019, Created file
Write a program that prints the numbers from 1 - 100 inclusive.
For multiples of three, print "Fizz", multiples of five, print "Buzz."
Numbers that are multiples of both, print "FizzBuzz."
'''

def fizz_buzz(n):
for num in range(n):
if num % 3 == 0 and num % 5 == 0:
msg = "FizzBuzz"
elif num % 3 == 0:
msg = "Fizz"
elif num % 5 == 0:
msg = "Buzz"
else:
msg = num
print(msg)

fizz_buzz(101)
18 changes: 18 additions & 0 deletions students/visokoo/lesson2_assignments/front_times.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 2 - front_times.py
Author: visokoo | Created: 1/16/2019
ChangeLog: 1/16/2019, Created file
Given a string and a non-negative int n, we'll say that the front of the string is the first 3 chars, or whatever is there if the string is less than length 3. Return n copies of the front;
front_times('Chocolate', 2) → 'ChoCho'
front_times('Chocolate', 3) → 'ChoChoCho'
front_times('Abc', 3) → 'AbcAbcAbc'
----------------------------------------------------
'''

def front_times(str, n):
front = str[:3]
return front * n
53 changes: 53 additions & 0 deletions students/visokoo/lesson2_assignments/grid_printer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'''
----------------------------------------------------
Assignment: grid_printer.py
Author: visokoo | Created: 1/16/2019
ChangeLog: 1/16/2019, Created file
Write a function that draws a grid like the following:
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
----------------------------------------------------
'''

def borders(n):
return " + " + " - " * n

def pillars(n):
return " | " + " " * (n * 3)

def grid_printer(n):
print(borders(n) * 2, "+")
for i in range(n):
print(pillars(n) * 2, "|", sep=" ")
print(borders(n) * 2, "+")
for i in range(n):
print(pillars(n) * 2, "|", sep=" ")
print(borders(n) * 2, "+")

def fancy_grid_printer(table_size, grid_size):
print(borders(grid_size) * table_size, "+")
for i in range(table_size):
for j in range(grid_size):
print(pillars(grid_size) * table_size, "|", sep=" ")
print(borders(grid_size) * table_size, "+")

while True:
prompt = input("Standard 2x2 table or fancy table?" + "\n" + "Options: standard/fancy/exit ")
if prompt.lower() == "standard":
size = input("Pick a size for your table, larger the number, larger the table. 1 - infinity ")
grid_printer(int(size))
elif prompt.lower() == "fancy":
total_table_size = input("Number of rows and columns? 1 - infinity ")
width = input("Width of each grid? 1 - infinity ")
fancy_grid_printer(int(total_table_size), int(width))
else: break
86 changes: 86 additions & 0 deletions students/visokoo/lesson2_assignments/series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'''
----------------------------------------------------
Assignment: series.py
Author: visokoo | Created: 1/17/2019
ChangeLog: 1/17/2019, Created file
Write 3 functions: fibonacci, lucas, and sum_series and some tests
for the functionality.
Fibonacci:
The Fibonacci Series is a numeric series starting with the integers 0 and 1.
In this series, the next integer is determined by summing the previous two.
This gives us:
0, 1, 1, 2, 3, 5, 8, 13, ...
Lucas:
The Lucas Numbers are a related series of integers that start with the values
2 and 1 rather than 0 and 1. The resulting series looks like this:
2, 1, 3, 4, 7, 11, 18, 29, ...
sum_series:
Create a function with one required parameter and two optional parameters. The required
parameter will determine which element in the series to print. The two optional parameters
will have default values of 0 and 1 and will determine the first two values for the series
to be produced.
'''

def fibonacci(n):
'''
fib(n) = fib(n-2) + fib(n-1)
Given the value n, call the sum_series function with that value
and return the fibonacci sequence at the nth index
'''
return sum_series(n)

def lucas(n):
'''
Formula is the same as fib, but starting values are 2 and 1 respectively
Given the value n, call the sum_series function with that value and
return the lucas sequence at the nth index
'''
return sum_series(n, v1=2, v2=0)

def sum_series(n, v1=0, v2=1):
'''
compute the nth value of a summation series.
:param v1=0: value of zeroth element in the series
:param v2=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 v1 is 2:
if n == 0:
return 2
elif n == 1:
return 1
else:
return sum_series(n - 2, v1=v1, v2=v2) + sum_series(n - 1, v1=v1, v2=v2)
else:
if n > 1:
return sum_series(n - 2) + sum_series(n - 1)
return n

if __name__ == "__main__":
# run some tests to make sure the fibonacci() is returning expected values.
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
# run some tests to make sure the lucas() is returning expected values.
assert lucas(0) == 2
assert lucas(1) == 1
assert lucas(4) == 7
# make sure sum_series outputs match fibonacci() and lucas() outputs.
assert sum_series(5) == fibonacci(5)
assert sum_series(5, 2, 1) == lucas(5)

print("Tests passed.")
21 changes: 21 additions & 0 deletions students/visokoo/lesson2_assignments/string_bits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 2 - string_bits.py
Author: visokoo | Created: 1/16/2019
ChangeLog: 1/16/2019, Created file
Given a string, return a new string made of every other char starting with the first, so "Hello" yields "Hlo".
string_bits('Hello') → 'Hlo'
string_bits('Hi') → 'H'
string_bits('Heeololeo') → 'Hello'
----------------------------------------------------
'''

def string_bits(str):
new_str = ""
for position in range(0, len(str), 2):
new_str += str[position]
return new_str
17 changes: 17 additions & 0 deletions students/visokoo/lesson2_assignments/string_times.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'''
----------------------------------------------------
Assignment: Python Push Ups - Warmup Part 2 - string_times.py
Author: visokoo | Created: 1/16/2019
ChangeLog: 1/16/2019, Created file
Given a string and a non-negative int n, return a larger string that is n copies of the original string.
string_times('Hi', 2) → 'HiHi'
string_times('Hi', 3) → 'HiHiHi'
string_times('Hi', 1) → 'Hi'
----------------------------------------------------
'''

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