Advertisement
teslariu

ejemplos clase 1

Aug 8th, 2023
1,034
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 1 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Colecciones: son un conjunto de dos o mas datos en Python
  5. * listas, tuplas, diccionarios, conjuntos, etc
  6.  
  7. LAS CADENAS SON COLECCIONES
  8.  
  9. TODAS LAS COLECCIONES SON ITERABLES (se pueden recorrer)
  10. Otras propiedades son inmutabilidad y orden
  11. listas: mutables y ordenadas
  12. tuplas: inmutables y ordenadas
  13. diccionarios: mutables y sin orden
  14. cadenas: inmutables y ordenadas
  15.  
  16. Funciones:
  17. 1) generales: print(), del(), type(), int(), float(), bool(). etc
  18. 2) de colecciones: len(), max(), min(), sum()
  19. 3) de clase:
  20.   ej: listas: l = [1,2,3] l.clear(), l.append(),....
  21.  
  22.  
  23.  
  24. Estructuras lógicas:
  25. Para ser Turing completo: 1 condicional, 1 bucle definido y 1 bucle indefinido
  26.  
  27. # if, for, while
  28.  
  29. # script que pide una edad y responde si es mayor o no
  30. edad = int(input("Edad: "))
  31.  
  32. if edad >= 18:
  33.    print("Mayor de edad")
  34. else:
  35.    print("Menor de edad")
  36.  
  37. # script que pide un nro y responde si es positvo, negativo o cero
  38.  
  39. n = int(input("Número: "))
  40.  
  41. if n > 0:
  42.    print("Positivo")
  43.  
  44. elif n < 0:
  45.    print("negativo")
  46.  
  47. else:
  48.    print("Cero")
  49.  
  50.  
  51. # script que pide un numero y lo busca en una lista
  52. n = int(input("Número: "))
  53. lista = [1, 0, 2, 4, 56, 100, -23.5, 123]
  54.  
  55. if n in lista:
  56.    print("esta en la lista")
  57. else:
  58.    print("No está en la lista")
  59.  
  60.  
  61. # ej de while
  62.  
  63. # script que pide un numero no negativo y calcula su raiz cuadrada
  64. while True:
  65.    n = input("Ingrese un numero entero no negativo: ")
  66.    if n.isdecimal():
  67.        print(f"La raiz cuadrada de {int(n)} es {int(n)**(1/2):.3f}")
  68.        break
  69.    else:
  70.        print("Error")
  71.  
  72.  
  73. # imprimir una lista de nombres:
  74. nombres = ["ale", "juana", "ana","oscar"]
  75.  
  76. for nombre in nombres:
  77.    print(nombre)
  78.  
  79. # imprimir cuadrados y cubos de 1 al 1000
  80. for numero in range(1,1001,1):
  81.    print(numero, numero**2, numero**3)
  82. """
  83. # imprimir de a dos listas por vez
  84. nombres = ["ale", "juana", "ana","oscar"]
  85. edades = [13, 54, 33, 24]
  86.  
  87. for nombre,edad in zip(nombres, edades):
  88.     print(nombre,edad)
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement