Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- lista = [23, 23.4, True, "Hola"]
- notas = [10,5,8,9,7]
- palabra = "mariposa"
- numeros = [1,2,3,4,5,6,7,8,9,10]
- """
- i = 0
- while i < len(lista):
- print(lista[i])
- i = i + 1
- # fuentes de error del while:
- # inicializar mal el contador (i=0)
- # no incrementar el contador -> bucle infinito (no poner i = i + 1)
- # poner mal el tope (por ejemplo, i + len(lista) en lugar de len(lista)
- # POR TODO LO DE ARRIBA; LO MEJOR ES ITERAR CON UN FOR
- # el for controla todo lo de arriba automáticamente
- # El iterador es una variable con contenido semántico
- # TODA COLECCION ES ITERABLE (lista, string)
- # EL FOR NO TIENE POSIBILIDAD DE ERROR COMO EL WHILE PORQUE
- # EL INTERPRETE DE PYTHON HACE TODO EL SOLO
- for elemento in lista:
- print(elemento)
- for nota in notas: # for <iterador> in <iterable>:
- print(nota)
- for letra in palabra:
- print(letra,end=".")
- """
- for numero in range(2,101,2):
- # imprime todos los pares de 2 a 100 con sus cuadrados
- print(f"x={numero} cuadrado={numero**2}")
- # range(inicio, tope, salto)
- # range(inicio, tope) salto por defecto igual a 1
- # range(tope) inicio x defecto = 0, salto x defecto = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement