Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- Colecciones: son un conjunto de dos o mas datos en Python
- * listas, tuplas, diccionarios, conjuntos, etc
- LAS CADENAS SON COLECCIONES
- TODAS LAS COLECCIONES SON ITERABLES (se pueden recorrer)
- Otras propiedades son inmutabilidad y orden
- listas: mutables y ordenadas
- tuplas: inmutables y ordenadas
- diccionarios: mutables y sin orden
- cadenas: inmutables y ordenadas
- Funciones:
- 1) generales: print(), del(), type(), int(), float(), bool(). etc
- 2) de colecciones: len(), max(), min(), sum()
- 3) de clase:
- ej: listas: l = [1,2,3] l.clear(), l.append(),....
- Estructuras lógicas:
- Para ser Turing completo: 1 condicional, 1 bucle definido y 1 bucle indefinido
- # if, for, while
- # script que pide una edad y responde si es mayor o no
- edad = int(input("Edad: "))
- if edad >= 18:
- print("Mayor de edad")
- else:
- print("Menor de edad")
- # script que pide un nro y responde si es positvo, negativo o cero
- n = int(input("Número: "))
- if n > 0:
- print("Positivo")
- elif n < 0:
- print("negativo")
- else:
- print("Cero")
- # script que pide un numero y lo busca en una lista
- n = int(input("Número: "))
- lista = [1, 0, 2, 4, 56, 100, -23.5, 123]
- if n in lista:
- print("esta en la lista")
- else:
- print("No está en la lista")
- # ej de while
- # script que pide un numero no negativo y calcula su raiz cuadrada
- while True:
- n = input("Ingrese un numero entero no negativo: ")
- if n.isdecimal():
- print(f"La raiz cuadrada de {int(n)} es {int(n)**(1/2):.3f}")
- break
- else:
- print("Error")
- # imprimir una lista de nombres:
- nombres = ["ale", "juana", "ana","oscar"]
- for nombre in nombres:
- print(nombre)
- # imprimir cuadrados y cubos de 1 al 1000
- for numero in range(1,1001,1):
- print(numero, numero**2, numero**3)
- """
- # imprimir de a dos listas por vez
- nombres = ["ale", "juana", "ana","oscar"]
- edades = [13, 54, 33, 24]
- for nombre,edad in zip(nombres, edades):
- print(nombre,edad)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement