Author Archives: Pablo

Python conventions (Zen of Python)

                                                                                                                       @PablO_CVi

 Many years ago a Pythoneer Tim Peters succinctly channels the BDFL’s guiding principles for Python’s design into 20 aphorisms, only 19 of which have been written down.      

        “Beautiful is better than ugly.    

        Explicit is better than implicit.    

        Simple is better than complex.    

        Complex is better than complicated.    

        Flat is better than nested.    

        Sparse is better than dense.    

        Readability counts.    

        Special cases aren’t special enough to break the rules.    

        Although practicality beats purity.    

        Errors should never pass silently.    

        Unless explicitly silenced.    

        In the face of ambiguity, refuse the temptation to guess.    

        There should be one– and preferably only one –obvious way to do it.    

        Although that way may not be obvious at first unless you’re Dutch.    

        Now is better than never.     Although never is often better than *right* now.    

        If the implementation is hard to explain, it’s a bad idea.    

        If the implementation is easy to explain, it may be a good idea.     

        Namespaces are one honking great idea — let’s do more of those!”(2004, p1).

Recuperado de: https://www.python.org/dev/peps/pep-0020/

 

 

Untitled

                                                                                                                              @PablO_CVi

Question1:

Question2:

Almost There

 Almost There                                                                                                             @PablO_CVi

I have 28 Pints in Masterys and I need 40 , so I am going to work in these 12 points that I need, also I am going to do the Quiz and the WSQ each week. 

Almost There

Bonus Quiz

                                                                                                                                    @PablO_CVi

I have made my feedback to my teachers 😀

Quiz 10

                                                                                                                                    @PablO_CVi

Question 1: https://github.com/PablOCVi/Quiz-10/blob/master/q1.py

Create a function called findThrees that receives as a parameter a vector/array/list of numbers and returns the sum of all numbers in that vector/array/list that are evenly divisible by 3.

Question 2: https://github.com/PablOCVi/Quiz-10/blob/master/q2.py

Create a function called dotProduct that receives two vectors/arrays/lists of numbers (say v1 and v2). The function returns what is the dot product of the two vectors/arrays/lists.

 

Note1: If using vectors/lists, you must check that both vectors are the same size. If not, your function should print an error message (“Not same size vectors”) and return -1
Note2: If using arrays, you need to pass a third parameter which is the size of the arrays, you can assume both arrays are that same size.

Quiz 9

 Partial 2 Exam                                                                                                        @PablO_CVi

Question 1:https://github.com/PablOCVi/Quiz-9/blob/master/Partial_Exam1.py

Question 2:https://github.com/PablOCVi/Quiz-9/blob/master/Partial_Exam2.py

Question 3:https://github.com/PablOCVi/Quiz-9/blob/master/Partial_Exam3.py

Question 4:https://github.com/PablOCVi/Quiz-9/blob/master/Partial_Exam4.py

Estimating e

 Estimating e                                                                                                      @PablO_CVi

In this assignment you will estimate the mathematical constant e. You should create a function called calculuate_e which receives one parameter called precision that should specify the number of decimal points of accuracy.

Here is my code: 

def calculate_e(precision):

x = precision

e = (1+1/x)**x

return float(e)

precision=int(input(“How many decimals do you want?”))

a = calculate_e(precision)

round(a,precision)

print(“The estimate of the constant e is: “,a)

 

Babylonian Method

– Babylonian Method                                                                                              @PablO_CVi

In this assignment you will write a function to calculate the square root of a number using the Babylonian method. You can search for that method, it will be easy to find.

My code: https://github.com/PablOCVi/WSQ/blob/master/WSQ13.py

Greatest Common Divisor

– Greatest Common Divisor                                                                                  @PablO_CVi

Write a function to calculate the greatest common denominator of two positive integers using Euclid’s algorithm.

My code: https://github.com/PablOCVi/WSQ/blob/master/WSQ12.py

Yo Soy 196

– Yo Soy 196                                                                                                           @PablO_CVi

create a program that asks the user for two pieces of data:

  • The lower bound of the sequence
  • The upper bound of the sequence

 

Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196″