Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.
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
20 changes: 20 additions & 0 deletions .bash_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The original version is saved in .bash_profile.pysave

export PATH="/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH"

# Add git branch to prompts
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
source ~/.git-prompt.sh
source ~/.git-completion.bash

export PS1="\D{%F %T}\n\[\033[1;32m\]\u\[\033[1;32m\]@\[\033[1;32m\]\h\[\033[1;32m\] \[\033[32m\]\w\[\033[35m\]\$(parse_git_branch)\[\033[00m\] $"

#source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenv
echo ${VIRTUAL_ENV:+[`basename $VIRTUAL_ENV`]}
#someenv

export PROJECT_HOME=~/projects
export WORKON_HOME=~/.virtualenvs
source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh
55 changes: 55 additions & 0 deletions students/GioSV/Lesson 1/break_me.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#In the break_me.py file write four simple Python functions:
#Each function, when called, should cause an exception to happen
#Each function should result in one of the install package four most common exceptions you’ll find.
#For review: NameError, TypeError, SyntaxError, AttributeError
#Hint – the interpreter will quit when it hits a Exception – so you can comment out all but the one you are testing at the moment.
#Use the Python standard library reference on Built In ExceptionsLinks to an external site. as a reference
#https://docs.python.org/3/library/exceptions.html

# Attribute references
# An attribute reference is a primary followed by a period and a name:
# attributeref ::= primary "." identifier

# The primary must evaluate to an object of a type that supports attribute references, which most objects do.
# This object is then asked to produce the attribute whose name is the identifier. This production can be customized by overriding the __getattr__() method. If this attribute is not available, the exception AttributeError is raised. Otherwise, the type and value of the object produced is determined by the object. Multiple evaluations of the same attribute reference may yield different objects.
# CODE BEGINS
# Atrribute Error example (evaluate)
string1= "whatever"
string1.capitalze
# CODE ENDS
# This should come back with an attribute error, as I was suppose to type the attribute 'capitalize' and ended up misstyping it instead.
# Update: it worked!


# exception NameError
# Raised when a local or global name is not found. This applies only to unqualified names. The associated value is an error message that includes the name that could not be found.
# CODE BEGINS
# Name Error example (evaluate)
x= 5
z= x+y
z
# CODE ENDS
# I would understand this should come back with a name error, as y is not define and the operation is not possible.


# exception SyntaxError
# Raised when the parser encounters a syntax error. This may occur in an import statement, in a call to the built-in functions exec() or eval(), or when reading the initial script or standard input (also interactively).
# Instances of this class have attributes filename, lineno, offset and text for easier access to the details. str() of the exception instance returns only the message.
# Syntax Error example (evaluate)
x="hello_there"
a= 3
z=5x
# w= 5 x
# v= x a
# z, w and v provoke a syntax error, as you putting an integer next to a string does not comeup with a known solution.


# exception TypeError
# Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.
# This exception may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be. If an object is meant to support a given operation but has not yet provided an implementation, NotImplementedError is the proper exception to raise.
# Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError.
# Type Error example (evaluate)
x="hello_there"
a= 3
z=x + a
# Technically, this is a case of Type Error, as you cannot add an integer and a string.
27 changes: 27 additions & 0 deletions students/GioSV/Lesson 2/fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Step 1
# Create a new module series.py in the lesson02 folder in your student folder.
# In it, add a function called fibonacci.
# The function should have one parameter, n.
# The function should return the nth value in the fibonacci series.
# Ensure that your function has a well-formed docstring
# Note that the fibinacci series is naturally recursive – the value is defined by previous values:
# fib(n) = fib(n-2) + fib(n-1)
print("Please, call the function using fib(n), where n is the n'ieth number of the Fibonacci series")
def fib(n):
if n < 2:
return n
return fib(n-2) + fib(n-1)
print (fib)


# Example with n=4 --> fib(4)
# fib(4)=fib(3) + fib(2)
# fib(3)=fib(2) + fib(1)
# fib(2)=fib(1) + fib(0)
# fib(1)=1
# fib(0)=0
# Going back:
# fib(2)=1+0=1
# fib(3)=1+1=2
# fib(4)=2+1=3
# It worked.
10 changes: 10 additions & 0 deletions students/GioSV/Lesson 2/fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
for i in range(1,101):
fizz=0
buzz=0
if i%3==0 and i%5==0:
i="fizzbuzz"
elif i%3==0:
i="fizz"
elif i%5==0:
i="buzz"
print(i)
38 changes: 38 additions & 0 deletions students/GioSV/Lesson 2/grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Write a function that draws a grid like the following:
#
# + - - - - + - - - - +
# | | |
# | | |
# | | |
# | | |
# + - - - - + - - - - +
# | | |
# | | |
# | | |
# | | |
# + - - - - + - - - - +
#
#We gotta define two types of lines:
# 1. The lines from the beginning, middle and end of the grind.
# 2. The lines in between.
#
#I don't like the idea of printing everything in order and just have the exercise done in a manual way. That's why I'll try and do it in a different way.
#
#def grind()
#Defining line type 1:
line_1="+ " + 5*"- " + "+ " + 5*"- " + "+"
line_2="| " + 5*" " + "| " + 5*" " + "|"

altitude=5

print (line_1)

for i in range(altitude):
print (line_2)

print (line_1)

for i in range(altitude):
print (line_2)

print (line_1)
49 changes: 49 additions & 0 deletions students/GioSV/Lesson 2/grid_fun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Write a function that draws a grid like the following:
#
# + - - - - + - - - - +
# | | |
# | | |
# | | |
# | | |
# + - - - - + - - - - +
# | | |
# | | |
# | | |
# | | |
# + - - - - + - - - - +
#
#We gotta define two types of lines:
# 1. The lines from the beginning, middle and end of the grind.
# 2. The lines in between.
#
#I don't like the idea of printing everything in order and just have the exercise done in a manual way. That's why I'll try and do it in a different way.
#
#
#IN ORDER TO CALL THE FUNCTION, ONE MUST TYPE:
# grid("+ ","- ","| ")
#OR:
#
#
#
#
def grid(a,b,c):
#a comes to be "+"
#b comes to be "-"
#c comes to be "|"
#I will internally define them like that, just in case the function is called withouth arguments.

#Defining line type 1:
line_1=a + 5*b + a + 5*b + a
line_2=c + 5*" " + c + 5*" " + c

print (line_1)

for i in range(5):
print (line_2)

print (line_1)

for i in range(5):
print (line_2)

print (line_1)
88 changes: 88 additions & 0 deletions students/GioSV/Lesson 2/grid_fun2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Write a function that draws a grid like the following:
#
# + - - - - + - - - - +
# | | |
# | | |
# | | |
# | | |
# + - - - - + - - - - +
# | | |
# | | |
# | | |
# | | |
# + - - - - + - - - - +
#
#We gotta define two types of lines:
# 1. The lines from the beginning, middle and end of the grind.
# 2. The lines in between.
#
#I don't like the idea of printing everything in order and just have the exercise done in a manual way. That's why I'll try and do it in a different way.
#
#
#IN ORDER TO CALL THE FUNCTION, ONE MUST TYPE:
# grid("+ ","- ","| ")
#OR:
#
#
#
print("In order to call the function grid, please type 'grid(a,b,c)', where a, b and c are the symbols you want to input to make your grid.\n")
def grid(a,b,c):
#a comes to be "+"
#b comes to be "-"
#c comes to be "|"
#I will internally define them like that, just in case the function is called withouth arguments.

#Defining line type 1:
line_1=a +" "+ 5*(b+" ") + a +" " + 5*(b+" ") + a
line_2=c +" " + 5*" " + c + 5*" " +" " + c

print (line_1)

for i in range(5):
print (line_2)

print (line_1)

for i in range(5):
print (line_2)

print (line_1)


#While this function does what it must, now I gotta generalize this particular function in order for the user not to input three different values -related to the symbols in the grid- but only one.
#By studying the example grid as it is, it's easy to know that 11 is the number of symbols in a row, as it is the number of symbols in the colums that close the grid and in the center.the
#In this sense, the whole configuration should change to permit grids of different sizes.

print("If you're looking to call the function print_grid, you should type print_grid(n), where 'n' is the size of the grid you want to built. \n Note that the minimum size of the grid is 5 and, if you enter a number below 5, a grid(5) will be the output.\n Note that the numbers should be odds that equals 5 or above.")
def print_grid(n):
#The minimum configuration in a row to have an ordered grid is the following:
# +-+-+
#Hence, the minimum size should be 5.
#I will clarify this point by making a print statement.
size_a=0
size_b=0
size_c=0
if (n%2==0):
return("Please, enter an odd number")

a="+"
b="-"
c="|"
size=n
size_a= size - 2 #spaces of the grid that are left once the spaces for a have been taken.
size_c= size_a - 1 #spaces of the grid that are left once the spaces for c have been taken.
size_b= size_c -2 #spaces of the grid that are left once the minimum spaces for b have been taken.
line_1=a +" "+ (size_b+1)*(b+" ") + a +" " + (size_b+1)*(b+" ") + a
line_2=c +" " + (size_b+1)*" " + c + (size_b+1)*" " +" " + c
if n<5:
n=5

print (line_1)
for i in range(size_c//2):
print (line_2)
print (line_1)
for i in range(size_c//2):
print (line_2)
print (line_1)


22 changes: 22 additions & 0 deletions students/GioSV/Lesson 2/grid_fun3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def print_grid2(o,p):
#Where:
# o: number of rows and columns.
# p: number of elements between rows and columns.
#This one is actually easier.
a="+"
b="-"
c="|"
middle_line1=""
middle_line2=""

for k in range (o):
middle_line1+=p*(b+" ") + a +" "
middle_line2+=+ p*" "+c+" "

line_1=a +" " + middle_line1
line_2=c +" " + middle_line2
print (line_1)
for j in range (o):
for i in range(p):
print (line_2)
print (line_1)
7 changes: 7 additions & 0 deletions students/GioSV/Lesson 2/lucas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
print("Please, call the function using lucas(n), where n is the n'ieth number of the Fibonacci series")
def lucas(n):
if n == 0:
return(2)
elif n==1:
return(1)
return lucas(n-2) + lucas(n-1)
61 changes: 61 additions & 0 deletions students/GioSV/Lesson 2/series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
print("If the fibonacci series is required, please type fib(n), where n is the n'ieth number of the Fibonacci series\n\n")
def fib(n):
"""
Presents to the user the n'ieth number in the
Fibonacci series, where 'n' is a number input
by the user.
"""
if n < 2:
return n
return fib(n-2) + fib(n-1)


print("If the lucas series is required, please type lucas(n), where n is the n'ieth number of the Lucas series\n\n")
def lucas(n):
"""
Presents to the user the n'ieth number in the
Lucas series, where 'n' is a number input
by the user.
"""
if n == 0:
return(2)
elif n==1:
return(1)
return lucas(n-2) + lucas(n-1)


o=0
p=1
print("Finally, if a more general sum series is required, please type sum_series(n,o,p), where n is the n'ieth number of the sum series. Default values for 'o' and 'p' are 0 and 1, respectively.\n\n")
def sum_series(n,o,p):
"""
Presents to the user the n'ieth number in the
Sum series, where 'n' is a number input
by the user. The 'o' and 'p' optional values
are, by default, 0 and 1. If left this way, the
sum series will return the result of the n'ieth
number in the Fibonacci series. If changed, it
will return other series.
"""
if n == 0:
return(o)
elif n==1:
return(p)
return sum_series(n-2,o,p) + sum_series(n-1,o,p)

def main():
assert fib(30) == 832040
assert fib(2) == 1
assert fib(4) == 3
assert lucas(0) == 2
assert lucas(1) == 1
assert lucas(4) == 7
assert sum_series(3,0,1) == 2
assert sum_series(8,2,1) == 47
assert sum_series(5,3,7) == 44
assert sum_series(7,4,3) == 71
assert sum_series(4,2,1) == 7
print("Tests concluded. Everything in order.\n")

if __name__ == '__main__':
main()