Bucle for:
Ejemplo 1:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for i in [0, 1, 2]: | |
| print "Hola ", | |
| print("") | |
| print("Final") |

Ejemplo 2:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for i in []: | |
| print"Hola ", | |
| print("") | |
| print("Final") |

Ejemplo 3:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for i in [1, 1, 1]: | |
| print"Hola ", | |
| print("") | |
| print("Final") |

Ejemplo 4:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for _ in [0, 1, 2]: | |
| print"Hola ", | |
| print("") | |
| print("Final") |

Ejemplo 5:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for i in [3, 4, 5]: | |
| print "Hola. Ahora i vale ",i," y su cuadrado ",i**2 | |
| print("Final") |

Ejemplo 6:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for i in ["Alba", "Benito", 27]: | |
| print "Hola. Ahora i vale ",i | |
| print("Final") |

Ejemplo 7:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for numero in [0, 1, 2, 3]: | |
| print numero,"*",numero,"=",numero ** 2 | |
| print("Final") |

Ejemplo 8:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| i = 10 | |
| print"El bucle no ha comenzado. Ahora i vale",i | |
| for i in [0, 1, 2, 3, 4]: | |
| print i,"*",i,"=",i ** 2 | |
| print "El bucle ha terminado. Ahora i vale",i |

Ejemplo 9:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for i in [0, 1, 2]: | |
| print i,"*",i,"=",i ** 2 | |
| print("") | |
| for i in [0, 1, 2, 3]: | |
| print i,"*",i,"*",i,"=",i ** 3 |

Ejemplo 10:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for i in "AMIGO": | |
| print "Dame una",i | |
| print("¡AMIGO!") |

Ejemplo 11:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for i in range(3): | |
| print "Hola ", | |
| print("") | |
| print("Final") |

Ejemplo 12:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| for i in range(10): | |
| print "Hola ", | |
| print("") | |
| print("Final") |

Ejemplo 13:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| veces = int(input("¿Cuantas veces quiere que le salude? ")) | |
| for i in range(veces): | |
| print"Hola ", | |
| print("") | |
| print("Adios") |

Ejemplo 14:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| cuenta = 0 | |
| for i in range(1, 6): | |
| if i % 2 == 0: | |
| cuenta = cuenta + 1 | |
| print "Desde 1 hasta 5 hay ",cuenta," multiplos de 2" |

Ejemplo 15:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("Comienzo") | |
| suma = 0 | |
| for i in [1, 2, 3, 4]: | |
| suma = suma + i | |
| print "La suma de los numeros de 1 a 4 es",suma |

Uso del bucle While en python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def aumenta4(inicio,fin): | |
| while inicio <=fin: | |
| print inicio | |
| inicio = inicio+4 | |
| inicio = int (input("Ingrese el numero inicial: ")) | |
| fin = int (input("Ingrese el numero final: ")) | |
| aumenta4(inicio,fin) |

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sacarimpar(numeroin,numerofin): | |
| while numeroin<=numerofin: | |
| residuo=numeroin % 2 | |
| if residuo != 0: | |
| print'El numero es impar ', numeroin | |
| else: | |
| print'El numero es par ', numeroin | |
| numeroin = numeroin+1 | |
| numeroin = int(input('Dame el numero inicial: ')) | |
| numerofin = int(input("Hasta que numero saber impar: ")) | |
| sacarimpar(numeroin,numerofin) |
