Lo que pasa de vez en cuando

--Originally published at 101 For Tec

Hoy sucedió algo muy gracioso cuando intentaba entrar a un sitio web, el archivo no fue encontrado, pero…no salía la típica ventana que dice Error y un código que los mortales no entienden, sino que los diseñadores se molestaron en hacer una página para casos como esos. El link es: http://www.ibiblio.org/obp/thinkCSpy/chap11.htm#5

¿Qué tiene eso de interesante? todos lo idiomas que ponen y los dialectos

Echa un vistazo….

0 1 2 3 4 5 6 7 8

 

Referencias:

http://www.ibiblio.org/obp/thinkCSpy/chap11.htm#5


Jisho para tu, jisho para mua

--Originally published at 101 For Tec

Jisho 辞書, es la palabra japonesa para diccionario tranquilos, hoy no hablaré de cosas otakus…Hoy vengo a hablarles de los diccionarios en Python.

Un diccionario es similar a lo que en Java llamamos array, la diferencia radica en que podemos personalizar las keys  que son las posiciones, es decir los nombres de las keys no están limitadas a números, sino que puedes personalizarlas y ponerles el nombre que desees.

La segunda cosa son los niveles, no hay límite, es decir que puedes seguir y seguir guardando información en una key; ahora, ¿qué puedo guardar en una key? Puedes guardar lo que desees, inclusive objetos.

Ahora el formato, los diccionarios se ponen entre llaves ‘{}’ y para una posición específica de un diccionario se pone nombre[posición]

Aquí hay un ejemplo que Angel compartió en su blog

dictionary

Referencias:

http://www.tutorialspoint.com/python3/python_variable_types.htmhttps://angelmendozas.wordpress.com/2016/08/30/python-basic-types/


No, no es el de mate

--Originally published at 101 For Tec

Rangos, ¿qué es eso? Eso no es queso, es una función que crea sucesiones aritméticas. Así es como luce

range(m, n, k)

m es el punto de inicio

 es el límite superior, nunca se toca

es el espacio entre cada número

ahora que sabemos que es un rango ¿en qué se usa? la mayoría de veces se usa como interator en loops, sin embargo tiene mas aplicaciones dependiendo de lo que estés realizando

He aquí un ejemplo

ejemplo.PNG

Referencias:

http://pythoncentral.io/pythons-range-function-explained/

https://geekytheory.com/la-funcion-range-en-python


You wanna try?

--Originally published at 101 For Tec

“Any program input such as a user typing at a keyboard or a network connection – can potentially be the source of security vulnerabilities and disastrous bugs. All input should be treated as potentially dangerous.

Determined attackers can use carefully crafted input to cause programs to run unauthorized commands. This technique can be used to delete or damage data, run malicious programs, or obtain sensitive information.”

This is the reason we need to validate the inputs we include in a program, so that when we “try” to do something we “catch” the errors, exceptions etc. For this we literally use the commands try and catch. Here is one example

https://www.trinket.io/embed/python/50ed4f51fd

Also, we need to be careful using this and be sharp enough for catching all the possible exceptions so that it is very difficult to find a “whole” in our code.

References:

Python Tip: Validating user input as number (Integer)

http://cis1.towson.edu/~cssecinj/modules/cs0/cs0-input-validation-python/


What´s list?

--Originally published at 101 For Tec

Today I´m talking about lists, as I mention in a previous post, a list is a group of items that have a position. The syntax of the lists is like it follows:

name_of_the_list = [elements,elements]

The positions start at 0 and you call them like this

name_of_the_list [0]

Also you can modify them just calling the position and making it equal to the new value

list1[0]:  physics

or delete elements writing del before the position

del list1[2];

Also you´re able to do the basic operations

Python Expression Results Description
len([1, 2, 3]) 3 Length
[1, 2, 3] + [4, 5, 6] [1, 2, 3, 4, 5, 6] Concatenation
[‘Hi!’] * 4 [‘Hi!’, ‘Hi!’, ‘Hi!’, ‘Hi!’] Repetition
3 in [1, 2, 3] True Membership
for x in [1, 2, 3]: print x, 1 2 3 Iteration

or for more fun stuff check this:

https://www.tutorialspoint.com/python/python_lists.htm


I know that you know that I love you

--Originally published at 101 For Tec

Have you ever heard something like this? Well, in natural language is something common, and oh surprise, in programming also is. In programming we have something that is called recursive functions.

“Recursion is a method of programming or coding a problem, in which a function calls itself one or more times in its body. Usually, it is returning the return value of this function call. If a function definition satisfies the condition of recursion, we call this function a recursive function.

A recursive function has to fulfill an important condition to be used in a program: it has to terminate. A recursive function terminates, if with every recursive call the solution of the problem is downsized and moves towards a base case. A base case is a case, where the problem can be solved without further recursion. A recursion can end up in an infinite loop, if the base case is not met in the calls.”

Here is one example

This code throws the six first lines of the Pascal´s triangle:

pascal.PNG

References:

http://www.python-course.eu/python3_recursive_functions.php


So…you´re into this?

--Originally published at 101 For Tec

Nested loops ¿what are they? A nested loop is a loop within a loop, an inner loop within the body of an outer one. Is possible to realize this with all the different types of loops, with for´s, here is the basic structure:
nested_for_syntax

also with while’s

nested_while_syntax

with if else, and also combining them.

Here is one example of what you can do with nested loops:

nested.PNG

References:

https://www.tutorialspoint.com/python3/python_nested_loops.htm

http://tldp.org/LDP/abs/html/nestedloops.html


For

--Originally published at 101 For Tec

For

The flowchart of a for is like it follows:

for_1.PNG

This is the basic structure:

for_0.PNG

val is a certain value or ‘conditional’

Here is one example

for_2.PNG

for_3.PNG

Important information about for´s:

  • The for statement in Python has the ability to iterate over the items of any sequence, such as a list or a string.
  • If a sequence contains an expression list, it is evaluated first. Then, the first item in the sequence is assigned to the iterating variable iterating_var. Next, the statements block is executed. Each item in the list is assigned to iterating_var, and the statement(s) block is executed until the entire sequence is exhausted.

References:

http://www.programiz.com/python-programming

http://www.tutorialspoint.com/python3/


Fruit Loops the revenge

--Originally published at 101 For Tec

In this post I´ll explain the missing loops, those are: elif, while and for. So  let´s get started.

Elif

This is the flowchart of an elif

elif.jpg

this is how it works

elif.PNG

and here is one example

elif_1.jpg

Important information about elif:

  • The elif is short for else if.It allows us to check for multiple expressions.
  • If the condition for if is False, it checks the condition of the next elif block and so on.
  • If all the conditions are False, body of else is executed.
  • Only one block among the several if…elif…else blocks is executed according to the condition.
  • The if block can have only one else block. But it can have multiple elif blocks.

For

The flowchart of a for is like it follows:

for_1.PNG

This is the basic structure:

for_0.PNG

val is a certain value or ‘conditional’

Here is one example

for_2.PNG

for_3.PNG

Important information about for´s:

  • The for statement in Python has the ability to iterate over the items of any sequence, such as a list or a string.
  • If a sequence contains an expression list, it is evaluated first. Then, the first item in the sequence is assigned to the iterating variable iterating_var. Next, the statements block is executed. Each item in the list is assigned to iterating_var, and the statement(s) block is executed until the entire sequence is exhausted.

While

The flowchart of a while is this

while_0

This is the structure of a while

while_1

One example of while

while_2while_3

References:

http://www.programiz.com/python-programming

http://www.tutorialspoint.com/python3/