Using “For”

--Originally published at My B10g

The For looping

The same as the while it will repeat the code bellow but instead of checking if something is real it checks if the parameters are still in the given range like…
  for i in 10:
        print (i)


this will print the numbers from 1 to 9

The benefit from using for to while is that while requires more CPU so to make a more efficient code its better to use for.


Use of loops with “while”

--Originally published at My B10g

This code will explain what while loop can do.
 count = 0
 while (count < 9):
    print 'The count is:', count
    count = count + 1

 print "Good bye!"
while (This is true):
   this code will repeat
this help for when you need to repeat a process multiple times and for preference when you don´t know how many times you have to repeat it.


Nesting

--Originally published at My B10g

cuando usas una condicional (if,else,elif) puedes usar cuantos quieras dentro o afuera de otras condicionales ya que por lo general siempre hay una situación extraordinaria en la que tu código no funciona y requieres una acción para esa situación, así es como ocurren los bugs.

Captura de pantalla 2016-09-05 a las 11.11.07.png

esto se puede ver en mi código de como checar el mayor numero de palabras que están en orden alfabético. para esto necesita checar letra por letra pero en cuanto aparece una que no va tiene que guardar la ultima letra que leyó y compararla con el ultimo arreglo de letras que guardo y así saber cual es mas grande.


If, else or both

--Originally published at My B10g

El “if” en programación sirve para checar si algo es verdad o no y en caso de ser verdadero ejecuta la acción siguiente.

x=0
if x<10:

print ("x is smaller than 10")

output == ‘x is smaller than 10’

“else” se usa para que en el caso de que el “if ” sea falso se ejecuta la condición de “else”

siguiendo el ejemplo anterior…
x=10
else:
print("x is bigger or equal to 10")

output == ‘x is bigger or equal to 10’

el “elif” se usa cuando tienes mas de dos opciones en el que tienes que especificar mas tu condición

por ejemplo…

x=10
elif x==10:
print ("el numero es 10")

output == ‘el numero es 10’

 

53538266.jpg

 


Creating and using your own modules/libraries

--Originally published at My B10g

to create your own libraries you need some things first you need your file to end with the .py extension, then you need to write “def” followed by the name of your method and between “()” put the parameter which it will need if that´s the case, if not you just leave them empty.

def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print(b, end=' ')
a, b = b, a+b
print()
code by Python Software Foundation

you can put as many methods you want inside the same .py file so you just need to import he file you need.

e00d06ddef93233a9c74fda0ff434b7744d210d787252f4d3d49796914e4f02d

 


Proyecto Compu 1

--Originally published at My B10g

esta entrada de blog es para preguntar si a alguien le gustaría hacer equipo para hacer un proyecto mediano para este semestre, tengo algunas ideas de lo que puede ser pero también me gustaría escuchar las de ustedes y ver si quedamos de acuerdo.gbgijhjnhhirexxwhxb8.jpg


Importing and using modules/libraries

--Originally published at My B10g

I´m back now that i have access to internet again i can start to blow again and why am i writing in english i will switch now

bueno el fin de semana me quede sin luz por si se preguntaron porque dije lo anterior y pues ya estoy de regreso a aprender, los modules de python o librerías son archivos de python o con extension .py que importan funciones para facilitar trabajos, por ejemplo…

import math

double pi=math.pi

entonces para usarlo lo importamos “import…” y para usar algún método que este dentro de la librería mencionamos primero la librería agregamos un punto y llamamos a el método “math.pi”.

 

comenten sus dudas?

qMKXZKh.mp4


Calling functions and Creating functions

--Originally published at My B10g

para crear una función necesitas empezar con def que se refiere a que estas definiendo lo  que va a hacer tu función, luego la nombras para mandarla a llamar, luego seguido del nombre van paréntesis “()”que indican el tipo de variable que le vana pasar y terminas con “: ” e inmediatamente abajo de esto escribes lo que va a hacer la función una vez mandada a llamar. Las funciones suelen regresar algo por lo general y esto se hace con ” return” y lo que quieres regresar pero en el caso de que no regreses nada lo toma como un valor nulo (este no significa “0“).

para mandar a llamar la funcion vasta con escribir el nombre y poner entre paréntesis el valor que le vas a pasar (recuerda que sea del mismo tipo para no llamar a una funcion inexistente).

esto es todo lo que debes saber de funciones:)

P.d.(recuerda usar correctamente tu tabulador a partir de la linea despues del “:”)


Basic output (print) Basic user input (text based)

--Originally published at My B10g

this are the default ways to talk to the machine, i give him something it responds me.

print shows whatever is inside the brackets.

for input work the same but the other way, but with the exception that whatever I input it will be in string format and in the case i want to use it in any other format i have to transform this.