This one’s FOR you

--Originally published at Python & pugs

MTI4OTg2NTkwNDQwNjI1NDI2.gifThis post will go straight to the point , so watch out, lads.

For getting started, you’ll need first to state a list for “For

for

From that list you can print the numbers in it, also whenever you print a number, you can print other Strings, but they have to be inside of it too.

Example:

for2

Besides, you can also print numbers in a range you ask for:

for3

Not only integers, you can also use Strings:

for4


FORever ALONE

--Originally published at Coding The Future

Image via GIPHY

Today, I will share the very sad story of my relationship life: I am, and forever will be a forever alone. But that's ok. To be honest, I don't mind the single life. Love's just complicated for me.

But anyways, you are probably wondering why am I telling you this, which is probably useless. Well it kind of is useless, but today's topic, For Loops, got me thinking.

So, let's dive into today's topic: For Loops. Remember while loops? Well for loops are not so difference. Only difference is that this time, we know exactly how many times the loop needs to run.

Here's an example: Let's say we wanted to ask a user to enter their password, and we need the user to enter it twice. Since we know that the loop will run exactly twice, the most appropriate way to accomplish this is a for loop. Let's take a look at the following program:

password = ["pass1","pass2"]
i=0;

for counter in range(0,2):
⠀⠀password[counter] = input("Please enter your password: ")
⠀⠀i= i+1

if (password[0] == password[1]):
⠀⠀print("Both passwords match")
else:
⠀⠀print("Passwords do not match")

As you can see, the first two lines simply declare a list and an integer. The following lines is where the magic happens. As you can see, I started with the keyword for, and declared a counter variable called counter, followed by the key words in range and the range from which the loop will run. As you can see, this range is in brackets, and it says (0,2). Check the footnote to know why this means it will run twice.1 I end off with a colon.

The code bellow just asks the user for input, stores it in a list, and at the end of the loop Continue reading "FORever ALONE"

Bucle For:

--Originally published at Migue´s Blog

La estructura for sirve para repetir un bloque de instrucciones tantas veces como se encuentre un elemento.

Su estructura es la siguiente

For (variable) in (elemento)

(Cuerpo del ciclo)

Las palabras en negritas no cambian, la variable puede tomar cualquier nombre, una letra o una palabra, normalmente se utiliza la letra i.

El elemento indica las veces que se va a repetir el ciclo, si se escribe una palabra en cada repetición la variable tomará el valor de cada letra, si se escriben varios elementos como palabras o números la variable en cada repetición tomará el valor de cada elemento, también se puede escribir un rango para que se repita el número de veces del rango, o se puede escribir un rango entre dos números para que tome valores entre esos dos números.

Para poder obtenr una información más detallada y con más ejemplos puede visitar la página bucle for.

Para poder ejemplificar esto realicé un programa que cuenta el número de caracteres en una frase que ingrese el usuario.

captura-de-pantalla-de-2016-09-14-23-18-47

 

captura-de-pantalla-de-2016-09-14-23-19-37

Como en todos mis programas anteriores las primeras dos lineas sirven para crear un ciclo infinito y poder calcular diferentes valores.

captura-de-pantalla-de-2016-09-14-23-52-21

Después guardamos en la variable “y” la cadena de texto que vamos a analizar, lo tenemos que guardar asi para que se guarde como un sólo elemento.

También utilizamos un contador llamado letras que nos servirá para ir añadiendo 1 por cada vez que se repita el ciclo.

captura-de-pantalla-de-2016-09-14-23-55-48

Por último utilizamos el bucle for, como “y” lo almacenamos como 1 solo elemento, esto funciona igual que si escribieramos una sola palabra, por lo que el ciclo se repetira 1 vez por cada letra, y por cada repetición se añadirá 1 al contador.

Finalmente imprimimos el resultado final del contador.

captura-de-pantalla-de-2016-09-15-00-00-38

 

 

 

 


More loops, loops everywhere, FOR LOOP.

--Originally published at Newbie Programmer

giphy
Me when i see a loop

Welcome to another post, and another loop.

In this case we explain the FOR loop. The for loop is used for the same things as the While Loop, but the for loop is for finite loops.

You can use Lists.

untitleduntitled2

If you put, for example the print (“A value”) into the loop, the words “A value” can be printed with every number.

f3f4

Range function.

f5f6

If you put a third number in the (), this number activates a function that says steps of 2 in the range.

f7f8

And you can use slices (strings) for the for loops.

f9f10

Source: https://www.youtube.com/watch?v=xtXexPSfcZg&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M&index=7

 

 


FOR ALL THOSE PROCRASTINATORS

--Originally published at Coding The Future

If you are reading this right now, you were probably procrastinating, and just started studying for tomorrow's test, right?

Well, as always, I've got you covered. Here's a quick video summary of what you need to know for the first partial. I hope things are not too strange.

Good luck!

>>>for meow

--Originally published at Nihilistic Kirby

The most recent command for python I’ve learned is >>>for , and since I haven’t thought of a good use for it yet, here’s a cool example of what a cat would write on its own code (as my own interpretation told me):

formeowcode

Hoping the image is clear enough to read, there’s the example of the code I’m using to represent the command >>>for

And here’s the execution:

formeowex

In natural language this can be expressed as ‘For each given Meow, show a Meow followed by an order number’.