Skip to main content

Gil

I suck at programming.
I'm not a good student.

#mastery08 Python conventions (Zen of Python)

1 min read

The zen of python is, according to long time Pythoneer Tim Peters, a set of rules you have to follow or at least to take into account while coding in python which are:

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!

 

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

 

Gilberto Rogel García

#mastery04 Submit work via Blog RSS and GitHub

1 min read

This is an example of a work submission via blog RSS (Any post on this site is an example)

To submit a work via withknown blog:

1-Sign up to withknown and log in.

2-Click Post.

3- Add a title and whatever you want to include in your blogpost.

4-Click Publish.

;D

This is a work submission via Github:  https://gist.github.com/gilrg18/f9f5a9fe4b1842fcda3c

To submit a work in github:

1-Go to https://gist.github.com/ ,sign up and log in.

2-Write a gist description and a name for the file.

3-Copy and paste your code into the blank space.

4-Click the button that says Create public Gist in the down right corner.

:D

#WSQ09 Factorial Calculator #TC1014

1 min read

In this wsq i had to create a function that gets the factorial of a number that the user gives you. After that i made a while with two other whiles inside of it so the program can work as it should.

Link for my code:

https://gist.github.com/gilrg18/f9f5a9fe4b1842fcda3c

#mastery13 Importing and using Python modules

1 min read

An example of this can be found on my WSQ06, here's the part of the code where i imported a module:

import random imported the module random that in this case it produces a random intenger from a certain parameter 

value= random.randint(1,100) this line does is that the variable value will become a random integer (random.randint) from 1 to 100 (1,100)

print(value)

This program will show a random value from 1 to 100.

---

Another example is:

import math import the module math which has lots of functions that can be found here https://docs.python.org/2/library/math.html

pi=math.pi will take math.pi's value which  is equivalent to 3.1416...

print (pi)

This program will show:

3.141592653589793

#mastery12 Creating python functions

1 min read

I used this link to help me do this mastery: https://docs.python.org/2/tutorial/controlflow.html#defining-functions

It is also useful to read chapter 3 of the book “Think Python, How to Think Like a Computer Scientist”, 

You can see an example of this in my . Here's the code showing the function that i created

def osuma (num1,num2): you have to define your function, in this case it's osuma with num1 and num 2 as parameters

suma=num1+num2 is what the function does... this line must be idented so the function can work properly

return suma   return statement returns with a value from a function... this line must be idented so the function can work properly

 

num1 = int(input("Give me a number: ")) 

num2 = int(input ("Give me another number: "))

su=osuma(num1,num2) i called osuma function i defined in order for the variable to take the function's value

 

print ("The sum of your numbers is", su) 

 

#mastery11 Calling python functions

2 min read

I used this link to help me do this mastery: https://docs.python.org/2/tutorial/controlflow.html#defining-functions

It is also useful to read chapter 3 of the book “Think Python, How to Think Like a Computer Scientist”, 

You can see an example of this in my . Here's the code showing where i called the function that i defined:

def osuma (num1,num2): osuma

suma=num1+num2

return suma 

 

def oresta (num1,num2): oresta

resta=num1-num2

return resta

 

def omulti (num1,num2): omulti

multi=num1*num2

return multi

 

def odiv (num1,num2): odiv

div=num1/num2

return div

 

def orem(num1,num2): orem

rem= num1%num2

return rem

 

 

num1 = int(input("Give me a number: ")) 

num2 = int(input ("Give me another number: "))

i called every function i defined in order for the variable to take the functions value

su=osuma(num1,num2) i called osuma function i defined in order for the variable to take the function's value

res=oresta(num1,num2) i called oresta function i defined in order for the variable to take the function's value

mult=omulti(num1,num2) i called omulti function i defined in order for the variable to take the function's value

di=odiv(num1,num2) i called odiv function i defined in order for the variable to take the function's value

re=orem(num1,num2) i called orem function i defined in order for the variable to take the function's value

 

print ("The sum of your numbers is", su) 

print ("The difference of your numbers is", res) 

print ("The product of your numbers is", mult) 

print ("The division of your numbers is", int(di)) 

print("The remainder of the division of your numbers is", int(re)) 

 

#TC1014 #WSQ01 Setup python

1 min read

Installed python 3 for my programming class ;) 

I downloaded it from this link: https://www.python.org/downloads/

 

Mastery 01

1 min read

Just installed python, i used this link https://www.python.org/downloads/ and clicked the button that says "Download python 3.4.2" then i opened the python-3.4.2.msi and followed the instructions to install it successfully